
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>SpringBoot · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="springmvc框架.html" />
    
    
    <link rel="prev" href="Mybatis框架.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../java/001环境变量.html">
            
                <a href="../java/001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../java/002Java初体验.html">
            
                <a href="../java/002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../java/003变量命名及数据类型.html">
            
                <a href="../java/003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../java/004运算符.html">
            
                <a href="../java/004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../java/005选择结构.html">
            
                <a href="../java/005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../java/006循环结构.html">
            
                <a href="../java/006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../java/007数组.html">
            
                <a href="../java/007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../java/008类和对象方法.html">
            
                <a href="../java/008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../java/009构造方法.html">
            
                <a href="../java/009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../java/010封装与关键字static.html">
            
                <a href="../java/010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../java/011 继承.html">
            
                <a href="../java/011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../java/012方法重写.html">
            
                <a href="../java/012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../java/013多态.html">
            
                <a href="../java/013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../java/014抽象类抽象方法.html">
            
                <a href="../java/014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../java/015接口.html">
            
                <a href="../java/015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../java/016异常.html">
            
                <a href="../java/016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../java/017集合.html">
            
                <a href="../java/017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="../java/017集合2.html">
            
                <a href="../java/017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="../java/018泛型.html">
            
                <a href="../java/018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="../java/019Collections算法类.html">
            
                <a href="../java/019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="../java/020枚举.html">
            
                <a href="../java/020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="../java/021包装类.html">
            
                <a href="../java/021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="../java/022常用类.html">
            
                <a href="../java/022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="../java/023File类.html">
            
                <a href="../java/023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="../java/024IO流.html">
            
                <a href="../java/024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="../java/025多线程.html">
            
                <a href="../java/025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="../java/025多线程线程池.html">
            
                <a href="../java/025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="../java/026网络编程Socket.html">
            
                <a href="../java/026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="../java/027XML解析.html">
            
                <a href="../java/027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="../java/028 注解.html">
            
                <a href="../java/028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="../java/029 Lambda表达式.html">
            
                <a href="../java/029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="../java/029 反射.html">
            
                <a href="../java/029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="Mybatis框架.html">
            
                <a href="Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.6.2" data-path="SpringBoot.html">
            
                <a href="SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="springmvc框架.html">
            
                <a href="springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="spring框架.html">
            
                <a href="spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >SpringBoot</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="springboot">SpringBoot</h1>
<h2 id="spring-boot&#x662F;&#x4EC0;&#x4E48;">Spring Boot&#x662F;&#x4EC0;&#x4E48;</h2>
<p>&#x4F17;&#x6240;&#x5468;&#x77E5; Spring &#x5E94;&#x7528;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x5927;&#x91CF;&#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x5404;&#x79CD; XML &#x914D;&#x7F6E;&#x548C;&#x6CE8;&#x89E3;&#x914D;&#x7F6E;&#x8BA9;&#x4EBA;&#x773C;&#x82B1;&#x7F2D;&#x4E71;&#xFF0C;&#x4E14;&#x6781;&#x5BB9;&#x6613;&#x51FA;&#x9519;&#xFF0C;&#x56E0;&#x6B64; Spring &#x4E00;&#x5EA6;&#x88AB;&#x79F0;&#x4E3A;&#x201C;&#x914D;&#x7F6E;&#x5730;&#x72F1;&#x201D;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x7B80;&#x5316; Spring &#x5E94;&#x7528;&#x7684;&#x642D;&#x5EFA;&#x548C;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#xFF0C;Pivotal &#x56E2;&#x961F;&#x5728; Spring &#x57FA;&#x7840;&#x4E0A;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x5957;&#x5168;&#x65B0;&#x7684;&#x5F00;&#x6E90;&#x7684;&#x6846;&#x67B6;&#xFF0C;&#x5B83;&#x5C31;&#x662F; Spring Boot&#x3002;</p>
<p>Spring Boot &#x5177;&#x6709; Spring &#x4E00;&#x5207;&#x4F18;&#x79C0;&#x7279;&#x6027;&#xFF0C;Spring &#x80FD;&#x505A;&#x7684;&#x4E8B;&#xFF0C;Spring Boot &#x90FD;&#x53EF;&#x4EE5;&#x505A;&#xFF0C;&#x800C;&#x4E14;&#x4F7F;&#x7528;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#xFF0C;&#x529F;&#x80FD;&#x66F4;&#x52A0;&#x4E30;&#x5BCC;&#xFF0C;&#x6027;&#x80FD;&#x66F4;&#x52A0;&#x7A33;&#x5B9A;&#x800C;&#x5065;&#x58EE;&#x3002;&#x968F;&#x7740;&#x8FD1;&#x4E9B;&#x5E74;&#x6765;&#x5FAE;&#x670D;&#x52A1;&#x6280;&#x672F;&#x7684;&#x6D41;&#x884C;&#xFF0C;Spring Boot &#x4E5F;&#x6210;&#x4E3A;&#x4E86;&#x65F6;&#x4E0B;&#x7099;&#x624B;&#x53EF;&#x70ED;&#x7684;&#x6280;&#x672F;&#x3002;</p>
<h2 id="spring-boot-&#x7684;&#x7279;&#x70B9;">Spring Boot &#x7684;&#x7279;&#x70B9;</h2>
<p>Spring Boot &#x5177;&#x6709;&#x4EE5;&#x4E0B;&#x7279;&#x70B9;&#xFF1A;</p>
<h4 id="1-&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#x7684;-spring-&#x9879;&#x76EE;">1. &#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#x7684; Spring &#x9879;&#x76EE;</h4>
<p>Spring Boot &#x53EF;&#x4EE5;&#x4EE5; jar &#x5305;&#x7684;&#x5F62;&#x5F0F;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#xFF0C;Spring Boot &#x9879;&#x76EE;&#x53EA;&#x9700;&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x201C; java&#x2013;jar xx.jar&#x201D; &#x5373;&#x53EF;&#x8FD0;&#x884C;&#x3002;</p>
<h4 id="2-&#x5185;&#x5D4C;-servlet-&#x5BB9;&#x5668;">2. &#x5185;&#x5D4C; Servlet &#x5BB9;&#x5668;</h4>
<p>Spring Boot &#x4F7F;&#x7528;&#x5D4C;&#x5165;&#x5F0F;&#x7684; Servlet &#x5BB9;&#x5668;&#xFF08;&#x4F8B;&#x5982; Tomcat&#x3001;Jetty &#x6216;&#x8005; Undertow &#x7B49;&#xFF09;&#xFF0C;&#x5E94;&#x7528;&#x65E0;&#x9700;&#x6253;&#x6210; WAR &#x5305; &#x3002;</p>
<h4 id="3-&#x63D0;&#x4F9B;-starter-&#x7B80;&#x5316;-maven-&#x914D;&#x7F6E;">3. &#x63D0;&#x4F9B; starter &#x7B80;&#x5316; Maven &#x914D;&#x7F6E;</h4>
<p>Spring Boot &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x7CFB;&#x5217;&#x7684;&#x201C;starter&#x201D;&#x9879;&#x76EE;&#x5BF9;&#x8C61;&#x6A21;&#x578B;&#xFF08;POMS&#xFF09;&#x6765;&#x7B80;&#x5316; Maven &#x914D;&#x7F6E;&#x3002;</p>
<h4 id="4-&#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;">4. &#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;</h4>
<p>Spring Boot &#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x9ED8;&#x8BA4;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#xFF0C;&#x6765;&#x7B80;&#x5316;&#x9879;&#x76EE;&#x7684;&#x5F00;&#x53D1;&#xFF0C;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x4E5F;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4FEE;&#x6539;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#x3002;</p>
<h4 id="5-&#x81EA;&#x5E26;&#x5E94;&#x7528;&#x76D1;&#x63A7;">5. &#x81EA;&#x5E26;&#x5E94;&#x7528;&#x76D1;&#x63A7;</h4>
<p>Spring Boot &#x53EF;&#x4EE5;&#x5BF9;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x9879;&#x76EE;&#x63D0;&#x4F9B;&#x76D1;&#x63A7;&#x3002;</p>
<h4 id="6-&#x65E0;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x548C;-xml-&#x914D;&#x7F6E;">6. &#x65E0;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x548C; xml &#x914D;&#x7F6E;</h4>
<p>Spring Boot &#x4E0D;&#x9700;&#x8981;&#x4EFB;&#x4F55; xml &#x914D;&#x7F6E;&#x5373;&#x53EF;&#x5B9E;&#x73B0; Spring &#x7684;&#x6240;&#x6709;&#x914D;&#x7F6E;&#x3002;</p>
<h2 id="&#x914D;&#x7F6E;&#x5F00;&#x53D1;&#x73AF;&#x5883;">&#x914D;&#x7F6E;&#x5F00;&#x53D1;&#x73AF;&#x5883;</h2>
<p>&#x5728;&#x4F7F;&#x7528; Spring Boot &#x8FDB;&#x884C;&#x5F00;&#x53D1;&#x4E4B;&#x524D;&#xFF0C;&#x7B2C;&#x4E00;&#x4EF6;&#x4E8B;&#x5C31;&#x662F;&#x914D;&#x7F6E;&#x597D;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x3002;&#x5DE5;&#x6B32;&#x5584;&#x5176;&#x4E8B;&#xFF0C;&#x5FC5;&#x5148;&#x5229;&#x5176;&#x5668;&#xFF0C;IDE&#xFF08;&#x96C6;&#x6210;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#xFF09;&#x7684;&#x9009;&#x62E9;&#x76F8;&#x5F53;&#x91CD;&#x8981;&#xFF0C;&#x76EE;&#x524D;&#x5E02;&#x9762;&#x4E0A;&#x6709;&#x5F88;&#x591A;&#x4F18;&#x79C0;&#x7684; IDE &#x5F00;&#x53D1;&#x5DE5;&#x5177;&#xFF0C;&#x4F8B;&#x5982; IntelliJ IDEA&#x3001;Spring Tools&#x3001;Visual Studio Code &#x548C; Eclipse &#x7B49;&#x7B49;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x8BE5;&#x5982;&#x4F55;&#x9009;&#x62E9;&#x5462;&#xFF1F;</p>
<p>&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x6781;&#x529B;&#x63A8;&#x8350;&#x5927;&#x5BB6;&#x4F7F;&#x7528; IntelliJ IDEA&#xFF0C;&#x56E0;&#x4E3A;&#x76F8;&#x6BD4;&#x4E8E;&#x4E0E;&#x5176;&#x4ED6; IDE&#xFF0C;IntelliJ IDEA &#x5BF9; Spring Boot &#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x597D;&#x7684;&#x652F;&#x6301;&#x3002;Spring Boot &#x7248;&#x672C;&#x53CA;&#x5176;&#x73AF;&#x5883;&#x914D;&#x7F6E;&#x8981;&#x6C42;&#x5982;&#x4E0B;&#x8868;</p>
<p><img src="SpringBoot.assets/image-20211126160228420.png" alt="image-20211126160228420"></p>
<h2 id="&#x521B;&#x5EFA;-spring-boot-&#x9879;&#x76EE;">&#x521B;&#x5EFA; Spring Boot &#x9879;&#x76EE;</h2>
<p>&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x914D;&#x7F6E;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; Intellij IDEA &#x521B;&#x5EFA;&#x4E00;&#x4E2A; Spring Boot &#x9879;&#x76EE;&#x4E86;&#x3002; Intellij IDEA &#x4E00;&#x822C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x521B;&#x5EFA; Spring Boot &#x9879;&#x76EE;&#xFF1A;</p>
<ul>
<li>&#x4F7F;&#x7528; Maven &#x521B;&#x5EFA;</li>
<li>&#x4F7F;&#x7528; Spring Initializr &#x521B;&#x5EFA;</li>
</ul>
<h3 id="maven-&#x521B;&#x5EFA;spring-boot-&#x9879;&#x76EE;">Maven &#x521B;&#x5EFA;Spring Boot &#x9879;&#x76EE;</h3>
<ol>
<li><p>&#x5728; IntelliJ IDEA &#x6B22;&#x8FCE;&#x9875;&#x9762;&#x5DE6;&#x4FA7;&#x9009;&#x62E9; Project &#xFF0C;&#x7136;&#x540E;&#x5728;&#x53F3;&#x4FA7;&#x9009;&#x62E9; New Project&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/09415R461-0.png" alt="IDEA &#x6B22;&#x8FCE;&#x9875;&#x9762;"></p>
</li>
</ol>
<p>&#x6216;&#x8005;&#x5728; IntelliJ IDEA &#x5DE5;&#x4F5C;&#x533A;&#x4E0A;&#x65B9;&#x7684;&#x83DC;&#x5355;&#x680F;&#x4E2D;&#x9009;&#x62E9; File &#xFF0C;&#x5728;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x4E2D;&#x4E2D;&#x9009;&#x4E2D; New&#xFF0C;&#x7136;&#x540E;&#x9009;&#x62E9; Project&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/09415Tc3-1.png" alt="IDEA &#x65B0;&#x5EFA;Maven &#x9879;&#x76EE;1 " style="zoom: 80%;"></p>
<ol>
<li>&#x5728;&#x5DE6;&#x4FA7;&#x7684;&#x9009;&#x9879;&#x4E2D;&#x9009;&#x62E9; Maven&#xFF0C;&#x52FE;&#x9009; Create from archetype &#x9009;&#x9879;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x4E0B;&#x9762;&#x9009;&#x62E9;&#x5408;&#x9002;&#x7684; Maven Archetype&#xFF08;&#x6A21;&#x578B;&#xFF09;&#xFF0C;&#x6700;&#x540E;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684; Next &#x6309;&#x94AE;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</li>
</ol>
<p><img src="SpringBoot.assets/09415W0O-2.png" alt="IDEA &#x9009;&#x62E9; Maven &#x539F;&#x578B;"></p>
<blockquote>
<p><code>&#x6CE8;&#x610F;</code>&#xFF1A;&#x6B64;&#x5904;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4E0D;&#x52FE;&#x9009; Create from archetype &#x9009;&#x9879;&#xFF0C;&#x76F4;&#x63A5;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684; Next &#x6309;&#x94AE;&#xFF0C;&#x76F4;&#x63A5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684; Maven &#x9879;&#x76EE;</p>
</blockquote>
<ol>
<li>&#x5982;&#x56FE; 7 &#x6240;&#x793A;&#xFF0C;&#x5C55;&#x5F00; Artifact Coordinates &#xFF0C;&#x5206;&#x522B;&#x8F93;&#x5165;&#x9879;&#x76EE;&#x540D;&#x79F0;&#xFF08;name&#xFF09;&#x3001;&#x5B58;&#x50A8;&#x4F4D;&#x7F6E;&#xFF08;Location&#xFF09;&#x3001;GroupId&#x3001;ArtifactId &#x4EE5;&#x53CA; Version &#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x4FE1;&#x606F;&#x8F93;&#x5165;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x70B9;&#x51FB; Next &#x6309;&#x94AE;</li>
</ol>
<p><img src="SpringBoot.assets/09415R346-3.png" alt="IDEA &#x65B0;&#x5EFA; Maven &#x9879;&#x76EE;2"></p>
<p>4.&#x5728;&#x8BE5;&#x9875;&#x9762;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E; Maven &#x7684;&#x4E3B;&#x76EE;&#x5F55;&#x548C;&#x672C;&#x5730;&#x4ED3;&#x5E93;&#x4FE1;&#x606F;&#xFF0C;&#x9664;&#x6B64;&#x4E4B;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x5728;&#x4E0B;&#x9762;&#x7684;&#x5C5E;&#x6027;&#xFF08;Properties&#xFF09;&#x5217;&#x8868;&#x4E2D;&#xFF0C;&#x68C0;&#x67E5;&#x548C;&#x4FEE;&#x6539;&#x9879;&#x76EE;&#x7684;&#x4FE1;&#x606F;&#x3002;&#x914D;&#x7F6E;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x70B9;&#x51FB; Finish &#x6309;&#x94AE;&#xFF0C;&#x5B8C;&#x6210;&#x9879;&#x76EE;&#x7684;&#x521B;&#x5EFA;</p>
<p><img src="SpringBoot.assets/09415T5X-4.png" alt="IDEA &#x8BBE;&#x7F6E; Maven &#x4E3B;&#x76EE;&#x5F55;&#x548C;&#x672C;&#x5730;&#x4ED3;&#x5E93;"></p>
<p>5.&#x8FD4;&#x56DE; IntelliJ IDEA &#x5DE5;&#x4F5C;&#x533A;&#xFF0C;&#x4F1A;&#x53D1;&#x73B0; Maven &#x9879;&#x76EE;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#xFF0C;&#x5176;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5982;&#x56FE; 9 &#x6240;&#x793A;&#x3002;</p>
<p><img src="SpringBoot.assets/09415UL0-5.png" alt="IDEA Maven &#x9879;&#x76EE;&#x7ED3;&#x6784;"></p>
<p>6.&#x5728;&#x8BE5; Maven &#x9879;&#x76EE;&#x7684; pom.xml &#x4E2D;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#xFF0C;&#x5BFC;&#x5165; Spring Boot &#x76F8;&#x5173;&#x7684;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--&#x7EE7;&#x627F;springboot&#x7684;&#x7236;&#x5DE5;&#x7A0B;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.4.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>
<span class="hljs-comment">&lt;!--&#x5F15;&#x5165;web&#x4F9D;&#x8D56;  spring+springmvc--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

<span class="hljs-comment">&lt;!--    &#x9879;&#x76EE;&#x6253;jar&#x5305;&#x5FC5;&#x8981;&#x63D2;&#x4EF6;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>
</code></pre>
<ol>
<li>&#x5728; cn.kgc.springboot&#x5305;&#x4E0B;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; HelloWorldApplication &#x4E3B;&#x7A0B;&#x5E8F;&#xFF0C;&#x7528;&#x6765;&#x542F;&#x52A8; Spring Boot &#x5E94;&#x7528;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;</li>
</ol>
<pre><code class="lang-java">&lt;!--
     &#x6CE8;&#x89E3;&#x8BF4;&#x660E;:  &#x8BE5;&#x6CE8;&#x89E3;&#x662F;&#x7EC4;&#x5408;&#x6CE8;&#x89E3;
        <span class="hljs-meta">@SpringBootConfiguration</span>   &#x7528;&#x6765;&#x81EA;&#x52A8;&#x914D;&#x7F6E;spring&#x76F8;&#x5173;&#x73AF;&#x5883;  spring+springmvc
        <span class="hljs-meta">@EnableAutoConfiguration</span>   &#x5F00;&#x542F;&#x81EA;&#x52A8;&#x914D;&#x7F6E; &#x6838;&#x5FC3;&#x6CE8;&#x89E3;
        <span class="hljs-meta">@ComponentScan</span>               &#x7EC4;&#x4EF6;&#x626B;&#x63CF;   &#x53EA;&#x80FD;&#x626B;&#x63CF;&#x5F53;&#x524D;&#x5305;&#x548C;&#x5B50;&#x5305;
--&gt;

<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorldApplication</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(HelloWorldApplication.class, args);
    }
}
</code></pre>
<h3 id="spring-initializr-&#x521B;&#x5EFA;springboot&#x9879;&#x76EE;">Spring Initializr &#x521B;&#x5EFA;SpringBoot&#x9879;&#x76EE;</h3>
<p>IntelliJ IDEA &#x652F;&#x6301;&#x7528;&#x6237;&#x4F7F;&#x7528; Spring &#x9879;&#x76EE;&#x521B;&#x5EFA;&#x5411;&#x5BFC;&#xFF08;Spring Initializr &#xFF09;&#x5FEB;&#x901F;&#x5730;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Spring Boot &#x9879;&#x76EE;&#xFF0C;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;</p>
<p>1.&#x5728; IntelliJ IDEA &#x6B22;&#x8FCE;&#x9875;&#x9762;&#x5DE6;&#x4FA7;&#x9009;&#x62E9; Project &#xFF0C;&#x7136;&#x540E;&#x5728;&#x53F3;&#x4FA7;&#x9009;&#x62E9; New Project&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/113PB0Y-1.png" alt="IDEA &#x6B22;&#x8FCE;&#x9875;&#x9762;"></p>
<p>&#x6216;&#x8005;&#x5728; IntelliJ IDEA &#x5DE5;&#x4F5C;&#x533A;&#x4E0A;&#x65B9;&#x7684;&#x83DC;&#x5355;&#x680F;&#x4E2D;&#x9009;&#x62E9; File &#xFF0C;&#x5728;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x4E2D;&#x9009;&#x5219; New&#xFF0C;&#x7136;&#x540E;&#x9009;&#x62E9; Project&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/113P63627-2.png" alt="IDEA &#x65B0;&#x5EFA;Maven &#x9879;&#x76EE;1 "></p>
<p>2.&#x5728;&#x65B0;&#x5EFA;&#x5DE5;&#x7A0B;&#x754C;&#x9762;&#x5DE6;&#x4FA7;&#xFF0C;&#x9009;&#x62E9; Spring Initializr&#xFF0C;&#x9009;&#x62E9;&#x9879;&#x76EE;&#x7684; SDK &#x4E3A; 1.8&#xFF0C;&#x9009;&#x62E9; starter service URL &#x4E3A; <a href="http://start.spring.io&#xFF08;&#x9ED8;&#x8BA4;&#xFF09;&#xFF0C;&#x6700;&#x540E;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684;" target="_blank">http://start.spring.io&#xFF08;&#x9ED8;&#x8BA4;&#xFF09;&#xFF0C;&#x6700;&#x540E;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684;</a> Next &#x6309;&#x94AE;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</p>
<p><img src="SpringBoot.assets/113P620U-3.png" alt="initralizr"></p>
<p>3.IDEA &#x4F1A;&#x8FDE;&#x63A5;&#x7F51;&#x7EDC;&#xFF0C;&#x5E76;&#x6839;&#x636E; starter service URL &#x67E5;&#x8BE2; Spring Boot &#x7684;&#x5F53;&#x524D;&#x53EF;&#x7528;&#x7248;&#x672C;&#x548C;&#x7EC4;&#x4EF6;&#x5217;&#x8868;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/113P61351-4.png" alt="IDEA &#x8054;&#x7F51;&#x67E5;&#x8BE2; Springboot &#x53EF;&#x4EE5;&#x7528;&#x7248;&#x672C;&#x53CA;&#x7EC4;&#x4EF6;&#x5217;&#x8868;"></p>
<p>&#x5728; Spring Initializr Project Settings &#x4E2D;&#xFF0C;&#x8F93;&#x5165;&#x9879;&#x76EE;&#x7684; GroupId&#x3001;ArtifactId &#x7B49;&#x5185;&#x5BB9;&#xFF0C;&#x6CE8;&#x610F; Type &#x4E3A; Maven&#xFF0C;packaging &#x4E3A; jar&#xFF0C;Java version &#x5207;&#x6362;&#x4E3A; 8&#xFF08;&#x9ED8;&#x8BA4;&#x4E3A; 11&#xFF09;&#xFF0C;&#x6700;&#x540E;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684; Next &#x6309;&#x94AE;&#xFF0C;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6B65;</p>
<p><img src="SpringBoot.assets/113PC633-5.png" alt="Spring Boot Initializr Settings"></p>
<p>4.&#x5728; dependencise &#x754C;&#x9762;&#x4E2D;&#xFF0C;&#x9009;&#x62E9; Spring Boot &#x7684;&#x7248;&#x672C;&#x53CA;&#x6240;&#x4F9D;&#x8D56;&#x7684; Spring Boot &#x7EC4;&#x4EF6;&#xFF08;&#x4F8B;&#x5982; Spring Boot &#x7684;&#x7248;&#x672C;&#x4E3A; 2.4.5&#xFF0C; Spring Boot &#x7EC4;&#x4EF6;&#x4E3A; Web&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x70B9;&#x51FB;&#x4E0B;&#x65B9;&#x7684; Next &#x6309;&#x94AE;</p>
<p><img src="SpringBoot.assets/113P61F9-6.png" alt="IDEA &#x7EC4;&#x4EF6;&#x9009;&#x62E9;&#x548C;&#x7248;&#x672C;&#x5207;&#x6362;"></p>
<p>5.&#x6839;&#x636E;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x9879;&#x76EE;&#x540D;&#x79F0;&#x53CA;&#x9879;&#x76EE;&#x5B58;&#x50A8;&#x4F4D;&#x7F6E;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x6700;&#x540E;&#x70B9;&#x51FB; Finish &#x6309;&#x94AE;&#xFF0C;&#x5B8C;&#x6210; Spring Boot &#x9879;&#x76EE;&#x7684;&#x521B;&#x5EFA;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/113P62T7-7.png" alt="img"></p>
<p>6.&#x8FD4;&#x56DE; IDEA &#x5DE5;&#x4F5C;&#x533A;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230; Spring Boot &#x9879;&#x76EE; helloworld &#x5DF2;&#x7ECF;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#x3002;&#x8BE5;&#x9879;&#x76EE;&#x4E0D;&#x4F46;&#x5177;&#x6709;&#x5B8C;&#x6574;&#x7684;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#xFF0C;&#x8FD8;&#x6709;&#x5B8C;&#x6574;&#x7684; Maven &#x914D;&#x7F6E;&#xFF0C;&#x5E76;&#x9ED8;&#x8BA4;&#x751F;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; HelloworldApplication &#x7684;&#x4E3B;&#x542F;&#x52A8;&#x7A0B;&#x5E8F;</p>
<p><img src="SpringBoot.assets/113P632S-0.png" alt="Spring Boot &#x76EE;&#x5F55;&#x7ED3;&#x6784;"></p>
<p>&#x6B64;&#x65F6;&#xFF0C;&#x51E0;&#x4E4E;&#x6240;&#x6709;&#x7684;&#x51C6;&#x5907;&#x5DE5;&#x4F5C;&#x90FD;&#x5DF2;&#x7ECF;&#x51C6;&#x5907;&#x5C31;&#x7EEA;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x6CA1;&#x6709;&#x7F16;&#x5199;&#x4EFB;&#x4F55;&#x4EE3;&#x7801;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;&#x8BE5; Spring Boot &#x9879;&#x76EE;&#x8FD0;&#x884C;&#x8D77;&#x6765;&#x3002;</p>
<h3 id="&#x542F;&#x52A8;-spring-boot">&#x542F;&#x52A8; Spring Boot</h3>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Spring Boot &#x9879;&#x76EE;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <em>*</em>Application &#x7684;&#x4E3B;&#x7A0B;&#x5E8F;&#x542F;&#x52A8;&#x7C7B; &#xFF0C;&#x8BE5;&#x7C7B;&#x4E2D;&#x4F7F;&#x7528;&#x4E86;&#x4E00;&#x4E2A;&#x7EC4;&#x5408;&#x6CE8;&#x89E3; @SpringBootApplication&#xFF0C;&#x7528;&#x6765;&#x5F00;&#x542F; Spring Boot &#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#xFF0C;&#x53E6;&#x5916;&#x8BE5;&#x542F;&#x52A8;&#x7C7B;&#x4E2D;&#x5305;&#x542B;&#x4E00;&#x4E2A; main() &#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x6765;&#x542F;&#x52A8;&#x8BE5;&#x9879;&#x76EE;&#x3002;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#x542F;&#x52A8;&#x7C7B; HelloworldApplication &#x4E2D;&#x7684; main() &#x65B9;&#x6CD5;&#xFF0C;&#x4FBF;&#x53EF;&#x4EE5;&#x542F;&#x52A8;&#x8BE5;&#x9879;&#x76EE;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;</p>
<p><img src="SpringBoot.assets/113P614O-9.png" alt="Spring Boot helloworld"></p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;Spring Boot &#x5185;&#x90E8;&#x96C6;&#x6210;&#x4E86; Tomcat&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x4EBA;&#x4E3A;&#x624B;&#x52A8;&#x914D;&#x7F6E; Tomcat&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x53EA;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x5177;&#x4F53;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x5373;&#x53EF;&#x3002;</p>
</blockquote>
<p>&#x4E3A;&#x4E86;&#x80FD;&#x6BD4;&#x8F83;&#x7684;&#x6E05;&#x695A;&#x7684;&#x770B;&#x5230;&#x6548;&#x679C;&#xFF0C;&#x6211;&#x4EEC;&#x5728; cn.kgc.springboot &#x5305;&#x4E0B;&#x53C8;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; controller &#x5305;&#xFF0C;&#x5E76;&#x5728;&#x8BE5;&#x5305;&#x5185;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; HelloController &#x7684; Controller&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloController</span> </span>{
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/hello&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">hello</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Hello World!&quot;</span>;
    }
}
</code></pre>
<p>&#x91CD;&#x542F; Spring Boot &#x9879;&#x76EE;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x5730;&#x5740;&#x680F;&#x8BBF;&#x95EE; &#x201C;<a href="http://localhost:8080/hello&#x201D;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;" target="_blank">http://localhost:8080/hello&#x201D;&#xFF0C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#x56FE;</a></p>
<h2 id="spring-boot-starter&#x5165;&#x95E8;">Spring Boot starter&#x5165;&#x95E8;</h2>
<p>&#x4F20;&#x7EDF;&#x7684; Spring &#x9879;&#x76EE;&#x60F3;&#x8981;&#x8FD0;&#x884C;&#xFF0C;&#x4E0D;&#x4EC5;&#x9700;&#x8981;&#x5BFC;&#x5165;&#x5404;&#x79CD;&#x4F9D;&#x8D56;&#xFF0C;&#x8FD8;&#x8981;&#x5BF9;&#x5404;&#x79CD; XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x5341;&#x5206;&#x7E41;&#x7410;&#xFF0C;&#x4F46; Spring Boot &#x9879;&#x76EE;&#x5728;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x5373;&#x4F7F;&#x4E0D;&#x7F16;&#x5199;&#x4EFB;&#x4F55;&#x4EE3;&#x7801;&#xFF0C;&#x4E0D;&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x914D;&#x7F6E;&#x4E5F;&#x80FD;&#x591F;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#xFF0C;&#x8FD9;&#x90FD;&#x8981;&#x5F52;&#x529F;&#x4E8E; Spring Boot &#x7684; starter &#x673A;&#x5236;</p>
<p>Spring Boot &#x5C06;&#x65E5;&#x5E38;&#x4F01;&#x4E1A;&#x5E94;&#x7528;&#x7814;&#x53D1;&#x4E2D;&#x7684;&#x5404;&#x79CD;&#x573A;&#x666F;&#x90FD;&#x62BD;&#x53D6;&#x51FA;&#x6765;&#xFF0C;&#x505A;&#x6210;&#x4E00;&#x4E2A;&#x4E2A;&#x7684; starter&#xFF08;&#x542F;&#x52A8;&#x5668;&#xFF09;&#xFF0C;starter &#x4E2D;&#x6574;&#x5408;&#x4E86;&#x8BE5;&#x573A;&#x666F;&#x4E0B;&#x5404;&#x79CD;&#x53EF;&#x80FD;&#x7528;&#x5230;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x7528;&#x6237;&#x53EA;&#x9700;&#x8981;&#x5728; Maven &#x4E2D;&#x5F15;&#x5165; starter &#x4F9D;&#x8D56;&#xFF0C;SpringBoot &#x5C31;&#x80FD;&#x81EA;&#x52A8;&#x626B;&#x63CF;&#x5230;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x4FE1;&#x606F;&#x5E76;&#x542F;&#x52A8;&#x76F8;&#x5E94;&#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#x3002;starter &#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x81EA;&#x52A8;&#x914D;&#x7F6E;&#xFF0C;&#x8BA9;&#x7528;&#x6237;&#x6446;&#x8131;&#x4E86;&#x5904;&#x7406;&#x5404;&#x79CD;&#x4F9D;&#x8D56;&#x548C;&#x914D;&#x7F6E;&#x7684;&#x56F0;&#x6270;&#x3002;&#x6240;&#x6709;&#x8FD9;&#x4E9B; starter &#x90FD;&#x9075;&#x5FAA;&#x7740;&#x7EA6;&#x5B9A;&#x6210;&#x4FD7;&#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#xFF0C;&#x5E76;&#x5141;&#x8BB8;&#x7528;&#x6237;&#x8C03;&#x6574;&#x8FD9;&#x4E9B;&#x914D;&#x7F6E;&#xFF0C;&#x5373;&#x9075;&#x5FAA;&#x201C;&#x7EA6;&#x5B9A;&#x5927;&#x4E8E;&#x914D;&#x7F6E;&#x201D;&#x7684;&#x539F;&#x5219;</p>
<p>&#x5E76;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x7684; starter &#x90FD;&#x662F;&#x7531; Spring Boot &#x5B98;&#x65B9;&#x63D0;&#x4F9B;&#x7684;&#xFF0C;&#x4E5F;&#x6709;&#x90E8;&#x5206; starter &#x662F;&#x7B2C;&#x4E09;&#x65B9;&#x6280;&#x672F;&#x5382;&#x5546;&#x63D0;&#x4F9B;&#x7684;&#xFF0C;&#x4F8B;&#x5982; druid-spring-boot-starter &#x548C; mybatis-spring-boot-starter &#x7B49;&#x7B49;&#x3002;&#x5F53;&#x7136;&#x4E5F;&#x5B58;&#x5728;&#x4E2A;&#x522B;&#x7B2C;&#x4E09;&#x65B9;&#x6280;&#x672F;&#xFF0C;Spring Boot &#x5B98;&#x65B9;&#x6CA1;&#x63D0;&#x4F9B; starter&#xFF0C;&#x7B2C;&#x4E09;&#x65B9;&#x6280;&#x672F;&#x5382;&#x5546;&#x4E5F;&#x6CA1;&#x6709;&#x63D0;&#x4F9B; starter</p>
<p>&#x4EE5; spring-boot-starter-web &#x4E3A;&#x4F8B;&#xFF0C;&#x5B83;&#x80FD;&#x591F;&#x4E3A;&#x63D0;&#x4F9B; Web &#x5F00;&#x53D1;&#x573A;&#x666F;&#x6240;&#x9700;&#x8981;&#x7684;&#x51E0;&#x4E4E;&#x6240;&#x6709;&#x4F9D;&#x8D56;&#xFF0C;&#x56E0;&#x6B64;&#x5728;&#x4F7F;&#x7528; Spring Boot &#x5F00;&#x53D1; Web &#x9879;&#x76EE;&#x65F6;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5F15;&#x5165;&#x8BE5; Starter &#x5373;&#x53EF;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x989D;&#x5916;&#x5BFC;&#x5165; Web &#x670D;&#x52A1;&#x5668;&#x548C;&#x5176;&#x4ED6;&#x7684; Web &#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml">    <span class="hljs-comment">&lt;!--SpringBoot&#x7236;&#x9879;&#x76EE;&#x4F9D;&#x8D56;&#x7BA1;&#x7406;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.5.13<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">relativePath</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x5BFC;&#x5165; spring-boot-starter-web--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        ...
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span>
</code></pre>
<p>&#x60A8;&#x53EF;&#x80FD;&#x4F1A;&#x53D1;&#x73B0;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x5373;&#x5728;&#x4EE5;&#x4E0A; pom.xml &#x7684;&#x914D;&#x7F6E;&#x4E2D;&#xFF0C;&#x5F15;&#x5165;&#x4F9D;&#x8D56; spring-boot-starter-web &#x65F6;&#xFF0C;&#x5E76;&#x6CA1;&#x6709;&#x6307;&#x660E;&#x5176;&#x7248;&#x672C;&#xFF08;version&#xFF09;&#xFF0C;&#x4F46;&#x5728;&#x4F9D;&#x8D56;&#x6811;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5374;&#x770B;&#x5230;&#x6240;&#x6709;&#x7684;&#x4F9D;&#x8D56;&#x90FD;&#x5177;&#x6709;&#x7248;&#x672C;&#x4FE1;&#x606F;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E9B;&#x7248;&#x672C;&#x4FE1;&#x606F;&#x662F;&#x5728;&#x54EA;&#x91CC;&#x63A7;&#x5236;&#x7684;&#x5462;&#xFF1F;</p>
<p>&#x5176;&#x5B9E;&#xFF0C;&#x8FD9;&#x4E9B;&#x7248;&#x672C;&#x4FE1;&#x606F;&#x662F;&#x7531; spring-boot-starter-parent&#xFF08;&#x7248;&#x672C;&#x4EF2;&#x88C1;&#x4E2D;&#x5FC3;&#xFF09; &#x7EDF;&#x4E00;&#x63A7;&#x5236;&#x7684;&#x3002;</p>
<p><strong>spring-boot-starter-parent</strong></p>
<p>spring-boot-starter-parent &#x662F;&#x6240;&#x6709; Spring Boot &#x9879;&#x76EE;&#x7684;&#x7236;&#x7EA7;&#x4F9D;&#x8D56;&#xFF0C;&#x5B83;&#x88AB;&#x79F0;&#x4E3A; Spring Boot &#x7684;&#x7248;&#x672C;&#x4EF2;&#x88C1;&#x4E2D;&#x5FC3;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x9879;&#x76EE;&#x5185;&#x7684;&#x90E8;&#x5206;&#x5E38;&#x7528;&#x4F9D;&#x8D56;&#x8FDB;&#x884C;&#x7EDF;&#x4E00;&#x7BA1;&#x7406;&#x3002;</p>
<pre><code>&lt;!--SpringBoot&#x7236;&#x9879;&#x76EE;&#x4F9D;&#x8D56;&#x7BA1;&#x7406;--&gt;
&lt;parent&gt;  
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;   
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;    
    &lt;version&gt;2.4.5&lt;/version&gt;    
&lt;/parent&gt;
</code></pre><p>Spring Boot &#x9879;&#x76EE;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EE7;&#x627F; spring-boot-starter-parent &#x6765;&#x83B7;&#x5F97;&#x4E00;&#x4E9B;&#x5408;&#x7406;&#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#xFF0C;&#x5B83;&#x4E3B;&#x8981;&#x63D0;&#x4F9B;&#x4E86;&#x4EE5;&#x4E0B;&#x7279;&#x6027;&#xFF1A;</p>
<ul>
<li>&#x9ED8;&#x8BA4; JDK &#x7248;&#x672C;&#xFF08;Java 8&#xFF09;</li>
<li>&#x9ED8;&#x8BA4;&#x5B57;&#x7B26;&#x96C6;&#xFF08;UTF-8&#xFF09;</li>
<li>&#x4F9D;&#x8D56;&#x7BA1;&#x7406;&#x529F;&#x80FD;</li>
<li>&#x8D44;&#x6E90;&#x8FC7;&#x6EE4;</li>
<li>&#x9ED8;&#x8BA4;&#x63D2;&#x4EF6;&#x914D;&#x7F6E;</li>
<li>&#x8BC6;&#x522B; application.properties &#x548C; application.yml &#x7C7B;&#x578B;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</li>
</ul>
<h2 id="springboot&#x57FA;&#x672C;&#x8BBE;&#x7F6E;">SpringBoot&#x57FA;&#x672C;&#x8BBE;&#x7F6E;</h2>
<h3 id="61springboot&#x8BBE;&#x7F6E;&#x7AEF;&#x53E3;&#x53F7;">6.1SpringBoot&#x8BBE;&#x7F6E;&#x7AEF;&#x53E3;&#x53F7;</h3>
<pre><code class="lang-xml">server:
  port: 8989 #&#x914D;&#x7F6E;&#x7AEF;&#x53E3;
</code></pre>
<h3 id="62springboot&#x8BBE;&#x7F6E;&#x9879;&#x76EE;&#x540D;">6.2SpringBoot&#x8BBE;&#x7F6E;&#x9879;&#x76EE;&#x540D;</h3>
<pre><code class="lang-xml">server:
  servlet:
    context-path: /springboot   #&#x914D;&#x7F6E;&#x9879;&#x76EE;&#x7684;&#x865A;&#x62DF;&#x8DEF;&#x5F84;(&#x6839;&#x8DEF;&#x5F84;) &#x9879;&#x76EE;&#x540D;&#x4F7F;&#x7528;/&#x5F00;&#x5934;
</code></pre>
<h3 id="63springboot&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x62C6;&#x5206;">6.3SpringBoot&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x62C6;&#x5206;</h3>
<pre><code class="lang-xml">spring:
  profiles:
    active: dev  #&#x5F00;&#x53D1;&#x73AF;&#x5883;
</code></pre>
<p><img src="SpringBoot.assets/image-20211127150318533.png" alt="image-20211127150318533"></p>
<h3 id="64springboot&#x5F00;&#x542F;&#x65E5;&#x5FD7;">6.4SpringBoot&#x5F00;&#x542F;&#x65E5;&#x5FD7;</h3>
<pre><code class="lang-yaml"><span class="hljs-comment"># &#x663E;&#x793A;sql</span>
<span class="hljs-attr">logging:</span>
<span class="hljs-attr">  level:</span>
    cn.kgc.springboot.mapper: debug  <span class="hljs-comment">#&#x5F00;&#x542F;&#x65E5;&#x5FD7;</span>
</code></pre>
<h3 id="65springboot&#x5B9E;&#x73B0;&#x70ED;&#x90E8;&#x7F72;">6.5SpringBoot&#x5B9E;&#x73B0;&#x70ED;&#x90E8;&#x7F72;</h3>
<p>&#x5728;web&#x9879;&#x76EE;&#x7684;&#x5F00;&#x653E;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x901A;&#x5E38;&#x6211;&#x4EEC;&#x6BCF;&#x6B21;&#x4FEE;&#x6539;&#x5B8C;&#x4EE3;&#x7801;&#x90FD;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x542F;&#x52A8;&#x9879;&#x76EE;&#xFF0C;&#x5B9E;&#x73B0;&#x91CD;&#x65B0;&#x90E8;&#x7F72;&#x3002;&#x4F46;&#x662F;&#x968F;&#x7740;&#x9879;&#x76EE;&#x8D8A;&#x6765;&#x8D8A;&#x5E9E;&#x5927;&#xFF0C;&#x6BCF;&#x6B21;&#x542F;&#x52A8;&#x90FD;&#x662F;&#x4E00;&#x4E2A;&#x8D39;&#x65F6;&#x7684;&#x4E8B;&#x60C5;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x70ED;&#x90E8;&#x7F72;&#x662F;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x6784;&#x5EFA;&#x7684;&#x6280;&#x672F;&#xFF0C;&#x6709;&#x4E86;&#x70ED;&#x90E8;&#x7F72;&#xFF0C;&#x53EF;&#x4EE5;&#x6781;&#x5927;&#x63D0;&#x9AD8;&#x6211;&#x4EEC;&#x7684;&#x5F00;&#x53D1;&#x6548;&#x7387;</p>
<p><strong>spring-boot-devtools&#x5B9E;&#x73B0;&#x70ED;&#x90E8;&#x7F72;</strong></p>
<p>1.&#x5F15;&#x5165;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-devtools<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>2.&#x914D;&#x7F6E;maven&#x63D2;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">fork</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">fork</span>&gt;</span> <span class="hljs-comment">&lt;!-- &#x5982;&#x679C;devtools&#x4E0D;&#x751F;&#x6548;  &#x8BF7;&#x8BBE;&#x7F6E;&#x8BE5;&#x5C5E;&#x6027; --&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>
</code></pre>
<p>3.&#x914D;&#x7F6E;application.yml&#x6587;&#x4EF6;</p>
<pre><code class="lang-yml"><span class="hljs-attr">devtools:</span>
<span class="hljs-attr">  restart:</span>
<span class="hljs-attr">    enabled:</span> <span class="hljs-literal">true</span> <span class="hljs-comment">#&#x5F00;&#x542F;&#x70ED;&#x90E8;&#x7F72;</span>
</code></pre>
<p>4.&#x4FEE;&#x6539;idea&#x8BBE;&#x7F6E;</p>
<blockquote>
<p>File-Settings-Compiler &#x52FE;&#x9009; Build Project automatically</p>
</blockquote>
<p>5.&#x8BBE;&#x7F6E;Registry</p>
<blockquote>
<p>ctrl + shift + alt + / &#xFF0C;&#x9009;&#x62E9;Registry&#xFF0C;&#x52FE;&#x9009;Compiler autoMake allow when app running</p>
</blockquote>
<h3 id="66springboot&#x5F00;&#x542F;&#x5206;&#x9875;&#x67E5;&#x8BE2;">6.6SpringBoot&#x5F00;&#x542F;&#x5206;&#x9875;&#x67E5;&#x8BE2;</h3>
<p>1.&#x5F15;&#x5165;&#x4F9D;&#x8D56;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.12<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

----------------------------------------------
 <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.10<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>2.&#x914D;&#x7F6E;application.yml&#x6587;&#x4EF6;&#xFF08;&#x53EF;&#x4EE5;&#x4E0D;&#x914D;&#x7F6E;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#xFF09;</p>
<pre><code class="lang-yml"><span class="hljs-comment"># pageHelper&#x5206;&#x9875;&#x914D;&#x7F6E;</span>
<span class="hljs-attr">pagehelper:</span>
<span class="hljs-attr">  helper-dialect:</span> mysql  <span class="hljs-comment">#&#x6570;&#x636E;&#x5E93;&#x7C7B;&#x578B;</span>
<span class="hljs-attr">  reasonable:</span> <span class="hljs-literal">true</span>   <span class="hljs-comment">#&#x5206;&#x9875;&#x5408;&#x7406;&#x5316; page&lt;1 &#x67E5;&#x8BE2;&#x7B2C;&#x4E00;&#x9875; page &gt;pageNumber &#x67E5;&#x8BE2;&#x6700;&#x540E;&#x4E00;&#x9875;</span>
<span class="hljs-attr">  support-methods-arguments:</span> <span class="hljs-literal">true</span>  <span class="hljs-comment"># &#x652F;&#x6301;mapper&#x63A5;&#x53E3;&#x4F20;&#x9012;&#x53C2;&#x6570;&#x5F00;&#x542F;&#x5206;&#x9875;</span>
<span class="hljs-attr">  params:</span> count=countSql  <span class="hljs-comment">#&#x7528;&#x4E8E;&#x4ECE;&#x5BF9;&#x8C61;&#x4E2D;&#x6839;&#x636E;&#x5C5E;&#x6027;&#x540D;&#x53D6;&#x503C;</span>
</code></pre>
<p>3.&#x7F16;&#x5199;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x4E1A;&#x52A1;&#x5C42;&#xFF0C;&#x6301;&#x4E45;&#x5316;&#x5C42;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> PageInfo&lt;User&gt; <span class="hljs-title">getPage</span><span class="hljs-params">(<span class="hljs-keyword">int</span> pageNum, <span class="hljs-keyword">int</span> pageSize)</span> </span>{

    PageHelper.startPage(pageNum, pageSize);

    List&lt;User&gt; userList = userMapper.selectList();

    PageInfo&lt;User&gt; pageInfo = <span class="hljs-keyword">new</span> PageInfo&lt;&gt;(userList);

    <span class="hljs-keyword">return</span> pageInfo;
}
</code></pre>
<h2 id="springboot&#x5BF9;&#x8C61;&#x7BA1;&#x7406;">springBoot&#x5BF9;&#x8C61;&#x7BA1;&#x7406;</h2>
<ul>
<li><p>&#x7BA1;&#x7406;&#x5BF9;&#x8C61;</p>
<p><strong>spring&#x4E2D;&#x7BA1;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</strong></p>
<p>1.&#x4F7F;&#x7528;xml&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x6587;&#x4EF6;&#x4E2D;&#x4F7F;&#x7528;bean&#x6807;&#x7B7E;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#x7684;&#x7BA1;&#x7406;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;xxx.xxx.xxx&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p>2.&#x4F7F;&#x7528;&#x6CE8;&#x89E3; @Component @Controller @Service @Repository</p>
<p><strong>springboot&#x7BA1;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</strong></p>
<p>1.&#x4F7F;&#x7528;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<p>springboot&#x652F;&#x6301;&#x4F7F;&#x7528;@Configuration&#x6CE8;&#x89E3;&#x6DFB;&#x52A0;&#x5728;&#x914D;&#x7F6E;&#x7C7B;&#x4E0A;&#xFF0C;&#x8BE5;&#x7C7B;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x7C7B;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;spring&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x8BE5;&#x6CE8;&#x89E3;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x5728;&#x7C7B;&#x4E0A;&#x3002;&#x5728;&#x914D;&#x7F6E;&#x7C7B;&#x4E2D;&#x65B9;&#x6CD5;&#x4E0A;&#x4F7F;&#x7528;@Bean&#x6CE8;&#x89E3;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;spring&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;bean&#x6807;&#x7B7E;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyConfiguration</span></span>{
   <span class="hljs-meta">@Bean</span>
   <span class="hljs-function"><span class="hljs-keyword">public</span> User <span class="hljs-title">getUser</span><span class="hljs-params">()</span></span>{
       <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> User();
   }
   <span class="hljs-meta">@Bean</span>
   <span class="hljs-function"><span class="hljs-keyword">public</span> Student <span class="hljs-title">getStudent</span><span class="hljs-params">()</span></span>{
       <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Student();
   }
}
</code></pre>
<p>2.&#x4F7F;&#x7528;&#x539F;&#x59CB;&#x7684;spring&#x6CE8;&#x89E3; @Component @Controller @Service @Repository</p>
</li>
<li><p>&#x5C5E;&#x6027;&#x6CE8;&#x5165;</p>
<p>spring &#x539F;&#x59CB;&#x7684;&#x6CE8;&#x5165;&#x65B9;&#x5F0F;</p>
<p>1.set&#x65B9;&#x5F0F;</p>
<p>2.constructor</p>
<p>3.&#x81EA;&#x52A8;&#x6CE8;&#x5165;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">name:</span> tom
<span class="hljs-attr">age:</span> <span class="hljs-number">30</span>
<span class="hljs-attr">price:</span> <span class="hljs-number">23.5</span>
<span class="hljs-attr">sex:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">birth:</span> <span class="hljs-number">2021</span>/<span class="hljs-number">11</span>/<span class="hljs-number">28</span> <span class="hljs-number">12</span>:<span class="hljs-number">12</span>:<span class="hljs-number">12</span>
<span class="hljs-attr">array:</span> <span class="hljs-number">12</span>,<span class="hljs-number">13</span>,<span class="hljs-number">15</span>,<span class="hljs-number">17</span>
<span class="hljs-attr">list:</span> &#x674E;&#x56DB;,lisi,tom
<span class="hljs-attr">map:</span> <span class="hljs-string">&quot;{&apos;aa&apos;:30,&apos;bb&apos;:&apos;lisi&apos;}&quot;</span> <span class="hljs-comment"># &#x6CE8;&#x5165;map&#x4F7F;&#x7528;json&#x683C;&#x5F0F;  &#x53D6;&#x503C;&#x7684;&#x4E2A;&#x6570;#{${map}}</span>
</code></pre>
<p>&#x5BF9;&#x8C61;&#x7684;&#x6CE8;&#x5165;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">object:</span>
<span class="hljs-attr">  name:</span> lisi
<span class="hljs-attr">  age:</span> <span class="hljs-number">20</span>
<span class="hljs-attr">  birth:</span> <span class="hljs-number">2021</span>/<span class="hljs-number">11</span>/<span class="hljs-number">24</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/inject2&quot;</span>)
<span class="hljs-meta">@ConfigurationProperties</span>(<span class="hljs-string">&quot;object&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">InjectController2</span> </span>{

    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> Integer age;
    <span class="hljs-keyword">private</span> Date birth;

       <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>{
        <span class="hljs-keyword">this</span>.name = name;
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAge</span><span class="hljs-params">(Integer age)</span> </span>{
        <span class="hljs-keyword">this</span>.age = age;
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setBirth</span><span class="hljs-params">(Date birth)</span> </span>{
        <span class="hljs-keyword">this</span>.birth = birth;
    }
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/inject&quot;</span>)
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">inject</span><span class="hljs-params">()</span></span>{
        System.out.println(name);
        System.out.println(age);
        System.out.println(birth);
        <span class="hljs-keyword">return</span>  <span class="hljs-string">&quot;ok&quot;</span>;
    }
}
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x6DFB;&#x52A0;&#x4E00;&#x4E0B;&#x4F9D;&#x8D56;&#xFF0C;&#x53EF;&#x4EE5;&#x518D;&#x5199;yaml&#x6587;&#x4EF6;&#x65F6;&#x63D0;&#x793A;,&#x6D88;&#x9664;&#x7EA2;&#x8272;&#x7684;&#x8B66;&#x544A;&#x63D0;&#x793A;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-configuration-processor<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
</li>
</ul>
<h2 id="springboot&#x6574;&#x5408;jsp">springBoot&#x6574;&#x5408;JSP</h2>
<p>&#x5F15;&#x5165;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--        &#x6807;&#x51C6;&#x6807;&#x7B7E;&#x5E93;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>jstl<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jstl<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--        &#x8BA9;springboot&#x5185;&#x7F6E;&#x7684;tomcat&#x5177;&#x6709;&#x89E3;&#x6790;jsp&#x7684;&#x80FD;&#x529B;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.tomcat.embed<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>tomcat-embed-jasper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>&#x914D;&#x7F6E;&#x89C6;&#x56FE;&#x89E3;&#x6790;&#x5668;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">spring:</span>
<span class="hljs-attr">  mvc:</span>
<span class="hljs-attr">    view:</span>
<span class="hljs-attr">      prefix:</span> /
<span class="hljs-attr">      suffix:</span> .jsp
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x4E0D;&#x91CD;&#x542F;&#x9879;&#x76EE; &#x5237;&#x65B0;jsp&#x9875;&#x9762;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">server:</span>
<span class="hljs-attr">  servlet:</span>
<span class="hljs-attr">    jsp:</span>
<span class="hljs-attr">      init-parameters:</span>
<span class="hljs-attr">        development:</span> <span class="hljs-literal">true</span>  <span class="hljs-comment"># &#x4FEE;&#x6539;jsp&#x9875;&#x9762;&#x65E0;&#x9700;&#x91CD;&#x65B0;&#x542F;&#x52A8;&#x9879;&#x76EE;</span>
</code></pre>
<p>&#x96C6;&#x6210;&#x540E;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;jsp&#x9875;&#x9762;&#x89E3;&#x51B3;&#x65B9;&#x6848;</p>
<p>1.&#x6DFB;&#x52A0;&#x63D2;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resources</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x6CE8;&#x518C;webapp&#x76EE;&#x5F55;&#x4E3A;&#x8D44;&#x6E90;&#x76EE;&#x5F55;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">resource</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">directory</span>&gt;</span>src/main/webapp<span class="hljs-tag">&lt;/<span class="hljs-name">directory</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">targetPath</span>&gt;</span>META-INF/resources<span class="hljs-tag">&lt;/<span class="hljs-name">targetPath</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">includes</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">include</span>&gt;</span>**/*.*<span class="hljs-tag">&lt;/<span class="hljs-name">include</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">includes</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">resource</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">resources</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>
</code></pre>
<p>2.&#x8BBE;&#x7F6E;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;</p>
<p><img src="SpringBoot.assets/image-20220517224429059-1652798696565.png" alt="image-20220517224429059"></p>
<p>3.&#x63D2;&#x4EF6;&#x542F;&#x52A8;</p>
<p><img src="SpringBoot.assets/image-20220517224649038.png" alt="image-20220517224649038"></p>
<h2 id="springboot&#x6574;&#x5408;mybatis">SpringBoot&#x6574;&#x5408;MyBatis</h2>
<p>&#x5F15;&#x5165;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.47<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis.spring.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.1.3<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.12<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>&#x7F16;&#x5199;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">spring:</span>
<span class="hljs-attr">  datasource:</span>
<span class="hljs-attr">    type:</span> com.alibaba.druid.pool.DruidDataSource
<span class="hljs-attr">    driver-class-name:</span> com.mysql.jdbc.Driver
<span class="hljs-attr">    username:</span> root
<span class="hljs-attr">    password:</span> root
<span class="hljs-attr">    url:</span> jdbc:mysql://localhost:<span class="hljs-number">3306</span>/mybatis?serverTimezone=UTC&amp;characterEncoding=utf<span class="hljs-bullet">-8</span>
</code></pre>
<p>mybatis&#x914D;&#x7F6E;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">mybatis:</span>
<span class="hljs-attr">  mapper-locations:</span> classpath:mapper/*.xml  <span class="hljs-comment">#&#x8BBE;&#x7F6E;mapper&#x6587;&#x4EF6;&#x7684;&#x4F4D;&#x7F6E;</span>
<span class="hljs-attr">  type-aliases-package:</span> cn.kgc.springboot.entity <span class="hljs-comment"># &#x8D77;&#x522B;&#x540D;</span>
<span class="hljs-attr">  configuration:</span>
<span class="hljs-attr">    map-underscore-to-camel-case:</span> <span class="hljs-literal">true</span> <span class="hljs-comment">#&#x5F00;&#x542F;&#x9A7C;&#x5CF0;&#x547D;&#x540D;</span>
</code></pre>
<p>&#x8BBE;&#x7F6E;dao&#x63A5;&#x53E3;&#x7684;&#x626B;&#x63CF;</p>
<p>1.&#x5728;&#x5165;&#x53E3;&#x7C7B;&#x4E0A;&#x4F7F;&#x7528;&#x6CE8;&#x89E3;,&#x5B8C;&#x6210;&#x626B;&#x63CF;</p>
<pre><code class="lang-java"><span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-meta">@MapperScan</span>(<span class="hljs-string">&quot;cn.kgc.springboot.dao&quot;</span>) <span class="hljs-comment">//&#x626B;&#x63CF;dao&#x63A5;&#x53E3;&#x6240;&#x5728;&#x7684;&#x5305; &#x540C;&#x65F6;&#x751F;&#x6210;&#x4EE3;&#x7406;&#x5BF9;&#x8C61; &#x6CE8;&#x5165;spring&#x5BB9;&#x5668;</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Springday02Application</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(Springday02Application.class, args);
    }
}
</code></pre>
<h2 id="springboot&#x6574;&#x5408;redis">springBoot&#x6574;&#x5408;Redis</h2>
<p>Redis &#x662F;&#x5B8C;&#x5168;&#x5F00;&#x6E90;&#x7684;&#xFF0C;&#x9075;&#x5B88; BSD &#x534F;&#x8BAE;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x9AD8;&#x6027;&#x80FD;&#x7684; key-value &#x6570;&#x636E;&#x5E93;.</p>
<p><strong>Redis &#x4E0E;&#x5176;&#x4ED6; key - value &#x7F13;&#x5B58;&#x4EA7;&#x54C1;&#x6709;&#x4EE5;&#x4E0B;&#x4E09;&#x4E2A;&#x7279;&#x70B9;&#xFF1A;</strong></p>
<ul>
<li>Redis&#x652F;&#x6301;&#x6570;&#x636E;&#x7684;&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x4FDD;&#x5B58;&#x5728;&#x78C1;&#x76D8;&#x4E2D;&#xFF0C;&#x91CD;&#x542F;&#x7684;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x518D;&#x6B21;&#x52A0;&#x8F7D;&#x8FDB;&#x884C;&#x4F7F;&#x7528;&#x3002;</li>
<li>Redis&#x4E0D;&#x4EC5;&#x4EC5;&#x652F;&#x6301;&#x7B80;&#x5355;&#x7684;key-value&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x540C;&#x65F6;&#x8FD8;&#x63D0;&#x4F9B;list&#xFF0C;set&#xFF0C;zset&#xFF0C;hash&#x7B49;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7684;&#x5B58;&#x50A8;&#x3002;</li>
<li>Redis&#x652F;&#x6301;&#x6570;&#x636E;&#x7684;&#x5907;&#x4EFD;&#xFF0C;&#x5373;master-slave&#x6A21;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x5907;&#x4EFD;&#x3002;</li>
</ul>
<h3 id="redis-&#x7684;&#x4F18;&#x52BF;"><strong>Redis &#x7684;&#x4F18;&#x52BF;</strong></h3>
<ul>
<li>&#x6027;&#x80FD;&#x6781;&#x9AD8; &#x2013; Redis&#x80FD;&#x8BFB;&#x7684;&#x901F;&#x5EA6;&#x662F;110000&#x6B21;/s,&#x5199;&#x7684;&#x901F;&#x5EA6;&#x662F;81000&#x6B21;/s </li>
<li>&#x4E30;&#x5BCC;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x2013; Redis&#x652F;&#x6301;&#x4E8C;&#x8FDB;&#x5236;&#x6848;&#x4F8B;&#x7684; String, List, Hash, Set &#x53CA; zset&#x6570;&#x636E;&#x7C7B;&#x578B;&#x64CD;&#x4F5C;&#x3002;</li>
<li>&#x539F;&#x5B50; &#x2013; Redis&#x7684;&#x6240;&#x6709;&#x64CD;&#x4F5C;&#x90FD;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;&#xFF0C;&#x610F;&#x601D;&#x5C31;&#x662F;&#x8981;&#x4E48;&#x6210;&#x529F;&#x6267;&#x884C;&#x8981;&#x4E48;&#x5931;&#x8D25;&#x5B8C;&#x5168;&#x4E0D;&#x6267;&#x884C;&#x3002;&#x5355;&#x4E2A;&#x64CD;&#x4F5C;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;&#x3002;&#x591A;&#x4E2A;&#x64CD;&#x4F5C;&#x4E5F;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#xFF0C;&#x5373;&#x539F;&#x5B50;&#x6027;&#xFF0C;&#x901A;&#x8FC7;MULTI&#x548C;EXEC&#x6307;&#x4EE4;&#x5305;&#x8D77;&#x6765;&#x3002;</li>
<li>&#x4E30;&#x5BCC;&#x7684;&#x7279;&#x6027; &#x2013; Redis&#x8FD8;&#x652F;&#x6301; publish/subscribe, &#x901A;&#x77E5;, key &#x8FC7;&#x671F;&#x7B49;&#x7B49;&#x7279;&#x6027;</li>
<li>Redis &#x662F;&#x5355;&#x7EBF;&#x7A0B;&#x7684;&#xFF0C;6.0&#x7248;&#x672C;&#x5F00;&#x59CB;&#x652F;&#x6301;&#x5F00;&#x542F;&#x591A;&#x7EBF;&#x7A0B;&#x3002;</li>
</ul>
<h3 id="redis&#x5B89;&#x88C5;"><strong>Redis&#x5B89;&#x88C5;</strong></h3>
<p><strong>&#x4E0B;&#x8F7D;&#x5730;&#x5740;&#xFF1A;</strong><a href="https://github.com/tporadowski/redis/releases&#x3002;" target="_blank">https://github.com/tporadowski/redis/releases&#x3002;</a></p>
<p><img src="https://www.runoob.com/wp-content/uploads/2014/11/3B8D633F-14CE-42E3-B174-FCCD48B11FF3.jpg" alt="img"></p>
<p>&#x89E3;&#x538B;&#x4E0B;&#x8F7D;&#x540E;&#x7684;&#x538B;&#x7F29;&#x6587;&#x4EF6;&#xFF0C;&#x89E3;&#x538B;&#x540E;&#x6587;&#x4EF6;&#x5217;&#x8868;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="SpringBoot.assets/image-20220518171544575.png" alt="image-20220518171544575"></p>
<p>&#x4F7F;&#x7528;cmd&#x7A97;&#x53E3;&#x6253;&#x5F00;Redis</p>
<pre><code class="lang-java">redis-server.exe   redis.windows.conf   #&#x52A0;&#x8F7D;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x542F;&#x52A8;
</code></pre>
<p><img src="SpringBoot.assets/image-20220518171619678.png" alt="image-20220518171619678"></p>
<p><code>&#x6CE8;&#xFF1A;&#x542F;&#x52A8;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x8981;&#x5173;&#x95ED;&#x7A97;&#x53E3;&#xFF0C;&#x5173;&#x95ED;&#x7A97;&#x53E3;&#x670D;&#x52A1;&#x505C;&#x6B62;&#xFF01;</code></p>
<p><strong>&#x5B89;&#x88C5;Redis&#x6570;&#x636E;&#x5E93;&#x5BA2;&#x6237;&#x7AEF;</strong></p>
<p><img src="SpringBoot.assets/image-20220518171908610.png" alt="image-20220518171908610"></p>
<p><strong>&#x5E93;&#x76F8;&#x5173;&#x6307;&#x4EE4;&#xFF1A;</strong></p>
<pre><code class="lang-xml">flushdb  &#x6E05;&#x7A7A;&#x5F53;&#x524D;&#x5E93;

flushall  &#x6E05;&#x7A7A;&#x6240;&#x6709;&#x5E93;

select   1    &#x5207;&#x6362;&#x5E93;
</code></pre>
<p><strong>key&#x7684;&#x76F8;&#x5173;&#x6307;&#x4EE4;</strong>+</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x6307;&#x4EE4;</th>
<th style="text-align:left">&#x4F5C;&#x7528;</th>
<th>&#x8BED;&#x6CD5;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>del</strong></td>
<td style="text-align:left">&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;key</td>
<td>del   keyname</td>
</tr>
<tr>
<td style="text-align:left"><strong>exists</strong></td>
<td style="text-align:left">&#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;key&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;&#x591A;&#x4E2A;key&#x65F6;&#x6709;&#x4E00;&#x4E2A;&#x5B58;&#x5728;&#x5219;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE;1</td>
<td>exists keyname</td>
</tr>
<tr>
<td style="text-align:left"><strong>expire</strong></td>
<td style="text-align:left">&#x8BBE;&#x7F6E;key&#x7684;&#x751F;&#x5B58;&#x65F6;&#x95F4;    &#x5355;&#x4F4D; &#xFF1A;&#x79D2;</td>
<td>expire keyname  seconds</td>
</tr>
<tr>
<td style="text-align:left"><strong>key</strong>s</td>
<td style="text-align:left">&#x67E5;&#x8BE2;&#x6240;&#x6709;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#x7684;key  &#xFF1F;&#x5339;&#x914D;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;   *&#x5339;&#x914D;0-n&#x4E2A;&#x5B57;&#x7B26;    [] &#x6EE1;&#x8DB3;&#x5176;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;</td>
<td>key *    key  h?llo</td>
</tr>
<tr>
<td style="text-align:left"><strong>move</strong></td>
<td style="text-align:left">&#x5C06;key&#x79FB;&#x52A8;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x5E93;&#x4E2D;</td>
<td>move   keyname db</td>
</tr>
<tr>
<td style="text-align:left"><strong>pexpire</strong></td>
<td style="text-align:left">&#x8BBE;&#x7F6E;key&#x7684;&#x751F;&#x5B58;&#x65F6;&#x95F4;    &#x5355;&#x4F4D; &#xFF1A;&#x6BEB;&#x79D2;  &#x8BBE;&#x7F6E;&#x6210;&#x529F;&#x8FD4;&#x56DE;1   &#x5426;&#x5219;&#x8FD4;&#x56DE;0</td>
<td>pexpire keyname  milliseconds</td>
</tr>
<tr>
<td style="text-align:left"><strong>ttl</strong></td>
<td style="text-align:left">&#x4EE5;&#x79D2;&#x4E3A;&#x5355;&#x4F4D;&#x8FD4;&#x56DE;key&#x7684;&#x5269;&#x4F59;&#x751F;&#x5B58;&#x65F6;&#x95F4;&#xFF0C;&#x8FD4;&#x56DE;-1&#x8868;&#x793A;&#x6C38;&#x4E45;&#x5B58;&#x50A8;&#xFF0C;-2&#x8868;&#x793A;key&#x4E0D;&#x5B58;&#x5728;</td>
<td>ttl  keyname</td>
</tr>
<tr>
<td style="text-align:left"><strong>randomkey</strong></td>
<td style="text-align:left">&#x4ECE;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x968F;&#x673A;&#x7684;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;key</td>
<td>randomkey</td>
</tr>
<tr>
<td style="text-align:left"><strong>rename</strong></td>
<td style="text-align:left">&#x91CD;&#x547D;&#x540D;key&#xFF0C;&#x6210;&#x529F;&#x8FD4;&#x56DE;ok&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;</td>
<td>rename  key  newkey</td>
</tr>
<tr>
<td style="text-align:left"><strong>type</strong></td>
<td style="text-align:left">&#x8FD4;&#x56DE;key&#x6240;&#x5B58;&#x50A8;&#x7684;&#x503C;&#x7684;&#x7C7B;&#x578B;</td>
<td>type keyname</td>
</tr>
</tbody>
</table>
<h3 id="redis&#x6570;&#x636E;&#x7C7B;&#x578B;">Redis&#x6570;&#x636E;&#x7C7B;&#x578B;</h3>
<h4 id="1string&#xFF08;&#x5B57;&#x7B26;&#x4E32;&#xFF09;">1.String&#xFF08;&#x5B57;&#x7B26;&#x4E32;&#xFF09;</h4>
<ul>
<li>string &#x662F; redis &#x6700;&#x57FA;&#x672C;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x6210;&#x4E0E; Memcached &#x4E00;&#x6A21;&#x4E00;&#x6837;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x4E00;&#x4E2A; key &#x5BF9;&#x5E94;&#x4E00;&#x4E2A; value&#x3002;</li>
<li>string &#x7C7B;&#x578B;&#x662F;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x5168;&#x7684;&#x3002;&#x610F;&#x601D;&#x662F; redis &#x7684; string &#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4EFB;&#x4F55;&#x6570;&#x636E;&#x3002;&#x6BD4;&#x5982;jpg&#x56FE;&#x7247;&#x6216;&#x8005;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x5BF9;&#x8C61;&#x3002;</li>
<li>string &#x7C7B;&#x578B;&#x662F; Redis &#x6700;&#x57FA;&#x672C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;string &#x7C7B;&#x578B;&#x7684;&#x503C;&#x6700;&#x5927;&#x80FD;&#x5B58;&#x50A8; 512MB&#x3002;</li>
</ul>
<p>&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>SET</strong></td>
<td>&#x8BBE;&#x7F6E;&#x6307;&#x5B9A; key &#x7684;&#x503C;</td>
</tr>
<tr>
<td><strong>GET</strong></td>
<td>&#x83B7;&#x53D6;&#x6307;&#x5B9A; key &#x7684;&#x503C;&#x3002;</td>
</tr>
<tr>
<td><strong>GETRANGE</strong></td>
<td>&#x8FD4;&#x56DE; key &#x4E2D;&#x5B57;&#x7B26;&#x4E32;&#x503C;&#x7684;&#x5B50;&#x5B57;&#x7B26;</td>
</tr>
<tr>
<td><strong>GETSET</strong></td>
<td>&#x5C06;&#x7ED9;&#x5B9A; key &#x7684;&#x503C;&#x8BBE;&#x4E3A; value &#xFF0C;&#x5E76;&#x8FD4;&#x56DE; key &#x7684;&#x65E7;&#x503C;(old value)&#x3002;</td>
</tr>
<tr>
<td><strong>SETEX</strong></td>
<td>&#x5C06;&#x503C; value &#x5173;&#x8054;&#x5230; key &#xFF0C;&#x5E76;&#x5C06; key &#x7684;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#x8BBE;&#x4E3A; seconds (&#x4EE5;&#x79D2;&#x4E3A;&#x5355;&#x4F4D;)&#x3002;</td>
</tr>
<tr>
<td><strong>SETNX</strong></td>
<td>&#x53EA;&#x6709;&#x5728; key &#x4E0D;&#x5B58;&#x5728;&#x65F6;&#x8BBE;&#x7F6E; key &#x7684;&#x503C;</td>
</tr>
<tr>
<td><strong>STRLEN</strong></td>
<td>&#x8FD4;&#x56DE; key &#x6240;&#x50A8;&#x5B58;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x503C;&#x7684;&#x957F;&#x5EA6;&#x3002;</td>
</tr>
<tr>
<td><strong>MSET</strong></td>
<td>&#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A; key-value &#x5BF9;&#x3002;</td>
</tr>
<tr>
<td><strong>MSETNX</strong></td>
<td>&#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A; key-value &#x5BF9;&#xFF0C;&#x5F53;&#x4E14;&#x4EC5;&#x5F53;&#x6240;&#x6709;&#x7ED9;&#x5B9A; key &#x90FD;&#x4E0D;&#x5B58;&#x5728;</td>
</tr>
<tr>
<td><strong>INCR</strong></td>
<td>&#x5C06; key &#x4E2D;&#x50A8;&#x5B58;&#x7684;&#x6570;&#x5B57;&#x503C;&#x589E;&#x4E00;</td>
</tr>
<tr>
<td><strong>INCRBY</strong></td>
<td>&#x5C06; key &#x6240;&#x50A8;&#x5B58;&#x7684;&#x503C;&#x52A0;&#x4E0A;&#x7ED9;&#x5B9A;&#x7684;&#x589E;&#x91CF;&#x503C;&#xFF08;increment&#xFF09;</td>
</tr>
<tr>
<td><strong>INCRBYFLOAT</strong></td>
<td>&#x5C06; key &#x6240;&#x50A8;&#x5B58;&#x7684;&#x503C;&#x52A0;&#x4E0A;&#x7ED9;&#x5B9A;&#x7684;&#x6D6E;&#x70B9;&#x589E;&#x91CF;&#x503C;&#xFF08;increment&#xFF09;</td>
</tr>
<tr>
<td><strong>DECR</strong></td>
<td>&#x5C06; key &#x4E2D;&#x50A8;&#x5B58;&#x7684;&#x6570;&#x5B57;&#x503C;&#x51CF;&#x4E00;&#x3002;</td>
</tr>
<tr>
<td><strong>DECRBY</strong></td>
<td>key &#x6240;&#x50A8;&#x5B58;&#x7684;&#x503C;&#x51CF;&#x53BB;&#x7ED9;&#x5B9A;&#x7684;&#x51CF;&#x91CF;&#x503C;&#xFF08;decrement&#xFF09;</td>
</tr>
<tr>
<td><strong>APPEND</strong></td>
<td>&#x5982;&#x679C; key &#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x5E76;&#x4E14;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C; APPEND &#x547D;&#x4EE4;&#x5C06;&#x6307;&#x5B9A;&#x7684; value &#x8FFD;&#x52A0;&#x5230;&#x8BE5; key &#x539F;&#x6765;&#x503C;&#xFF08;value&#xFF09;&#x7684;&#x672B;&#x5C3E;</td>
</tr>
</tbody>
</table>
<h4 id="2hash&#xFF08;&#x54C8;&#x5E0C;&#xFF09;">2.Hash&#xFF08;&#x54C8;&#x5E0C;&#xFF09;</h4>
<ul>
<li>Redis hash &#x662F;&#x4E00;&#x4E2A;&#x952E;&#x503C;(key=&gt;value)&#x5BF9;&#x96C6;&#x5408;&#x3002;</li>
<li>Redis hash &#x662F;&#x4E00;&#x4E2A; string &#x7C7B;&#x578B;&#x7684; field &#x548C; value &#x7684;&#x6620;&#x5C04;&#x8868;&#xFF0C;hash &#x7279;&#x522B;&#x9002;&#x5408;&#x7528;&#x4E8E;&#x5B58;&#x50A8;&#x5BF9;&#x8C61;&#x3002;</li>
</ul>
<p>&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>hset</td>
<td>&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;key/value&#x5BF9;</td>
</tr>
<tr>
<td>hget</td>
<td>&#x83B7;&#x53D6;key&#x5BF9;&#x5E94;&#x7684;value</td>
</tr>
<tr>
<td>hgetall</td>
<td>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;key/value&#x5BF9;</td>
</tr>
<tr>
<td>hdel</td>
<td>&#x5220;&#x9664;&#x67D0;&#x4E2A;key/value&#x5BF9;</td>
</tr>
<tr>
<td>hexists</td>
<td>&#x5224;&#x65AD;&#x4E00;&#x4E2A;key&#x662F;&#x5426;&#x5B58;&#x5728;</td>
</tr>
<tr>
<td>hkeys</td>
<td>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;key</td>
</tr>
<tr>
<td>hvals</td>
<td>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;value</td>
</tr>
<tr>
<td>hmset</td>
<td>&#x8BBE;&#x7F6E;&#x591A;&#x4E2A;key/value</td>
</tr>
<tr>
<td>hmget</td>
<td>&#x83B7;&#x53D6;&#x591A;&#x4E2A;key&#x7684;value</td>
</tr>
<tr>
<td>hsetnx</td>
<td>&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;key&#x7684;&#x503C;</td>
</tr>
<tr>
<td>hincrby</td>
<td>&#x4E3A;value&#x7684;&#x503C;&#x8FDB;&#x884C;&#x52A0;&#x6CD5;&#x8FD0;&#x7B97;</td>
</tr>
<tr>
<td>hincrbyfloat</td>
<td>&#x4E3A;value&#x7684;&#x503C;&#x8FDB;&#x884C;&#x52A0;&#x6D6E;&#x70B9;&#x7C7B;&#x578B;&#x503C;&#x8FD0;&#x7B97;</td>
</tr>
</tbody>
</table>
<h4 id="3list&#xFF08;&#x5217;&#x8868;&#xFF09;">3.List&#xFF08;&#x5217;&#x8868;&#xFF09;</h4>
<ul>
<li>Redis &#x5217;&#x8868;&#x662F;&#x7B80;&#x5355;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5217;&#x8868;&#xFF0C;&#x6309;&#x7167;&#x63D2;&#x5165;&#x987A;&#x5E8F;&#x6392;&#x5E8F;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5230;&#x5217;&#x8868;&#x7684;&#x5934;&#x90E8;&#xFF08;&#x5DE6;&#x8FB9;&#xFF09;&#x6216;&#x8005;&#x5C3E;&#x90E8;&#xFF08;&#x53F3;&#x8FB9;&#xFF09;&#x3002;</li>
</ul>
<p>&#x64CD;&#x4F5C;&#x6307;&#x4EE4;</p>
<table>
<thead>
<tr>
<th><strong>&#x547D;&#x4EE4;</strong></th>
<th><strong>&#x63CF;&#x8FF0;</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>LINDEX</strong></td>
<td>&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x5143;&#x7D20;     lindex lists 0</td>
</tr>
<tr>
<td>**LINSERT key BEFORE\</td>
<td>AFTER**</td>
<td>&#x5728;&#x5217;&#x8868;&#x7684;&#x5143;&#x7D20;&#x524D;&#x6216;&#x8005;&#x540E;&#x63D2;&#x5165;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td><strong>LLEN</strong></td>
<td>&#x83B7;&#x53D6;&#x5217;&#x8868;&#x957F;&#x5EA6;</td>
</tr>
<tr>
<td><strong>LPOP</strong></td>
<td>&#x79FB;&#x51FA;&#x5E76;&#x83B7;&#x53D6;&#x5217;&#x8868;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td><strong>LPUSH</strong></td>
<td>&#x5C06;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x503C;&#x63D2;&#x5165;&#x5230;&#x5217;&#x8868;&#x5934;&#x90E8;</td>
</tr>
<tr>
<td><strong>LPUSHX</strong></td>
<td>&#x5C06;&#x4E00;&#x4E2A;&#x503C;&#x63D2;&#x5165;&#x5230;<strong>&#x5DF2;&#x5B58;&#x5728;</strong>&#x7684;&#x5217;&#x8868;&#x5934;&#x90E8;</td>
</tr>
<tr>
<td><strong>LRANGE</strong></td>
<td>&#x83B7;&#x53D6;&#x5217;&#x8868;&#x6307;&#x5B9A;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5143;&#x7D20;  &#xFF08;0 -1&#xFF09;</td>
</tr>
<tr>
<td><strong>LREM</strong></td>
<td>&#x79FB;&#x9664;&#x5217;&#x8868;&#x91CD;&#x590D;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td><strong>LSET</strong></td>
<td>&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x8BBE;&#x7F6E;&#x5217;&#x8868;&#x5143;&#x7D20;&#x7684;&#x503C; &#xFF0C;&#x4F46;&#x662F;&#x7D22;&#x5F15;&#x5FC5;&#x987B;&#x5B58;&#x5728;&#xFF0C;&#x5B9E;&#x8D28;&#x662F;&#x6839;&#x636E;&#x7D22;&#x5F15;&#x4FEE;&#x6539;&#x503C;</td>
</tr>
<tr>
<td><strong>LTRIM</strong></td>
<td>&#x5BF9;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x8FDB;&#x884C;&#x4FEE;&#x526A;(trim)&#xFF0C;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x8BA9;&#x5217;&#x8868;&#x53EA;&#x4FDD;&#x7559;&#x6307;&#x5B9A;&#x533A;&#x95F4;&#x5185;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x4E0D;&#x5728;&#x6307;&#x5B9A;&#x533A;&#x95F4;&#x4E4B;&#x5185;&#x7684;&#x5143;&#x7D20;&#x90FD;&#x5C06;&#x88AB;&#x5220;&#x9664;</td>
</tr>
<tr>
<td><strong>RPOP</strong></td>
<td>&#x79FB;&#x9664;&#x5217;&#x8868;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;&#x79FB;&#x9664;&#x7684;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td><strong>RPOPLPUSH</strong></td>
<td>&#x79FB;&#x9664;&#x5217;&#x8868;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x5C06;&#x8BE5;&#x5143;&#x7D20;&#x6DFB;&#x52A0;&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x5E76;&#x8FD4;&#x56DE;</td>
</tr>
<tr>
<td><strong>RPUSH</strong></td>
<td>&#x5728;&#x5217;&#x8868;&#x4E2D;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x503C;</td>
</tr>
<tr>
<td><strong>RPUSHX</strong></td>
<td>&#x4E3A;&#x5DF2;&#x5B58;&#x5728;&#x7684;&#x5217;&#x8868;&#x6DFB;&#x52A0;&#x503C;</td>
</tr>
</tbody>
</table>
<h4 id="4set&#xFF08;&#x96C6;&#x5408;&#xFF09;">4.Set&#xFF08;&#x96C6;&#x5408;&#xFF09;</h4>
<ul>
<li>Redis &#x7684; Set &#x662F; string &#x7C7B;&#x578B;&#x7684;&#x65E0;&#x5E8F;&#x96C6;&#x5408;&#x3002;</li>
<li>&#x96C6;&#x5408;&#x662F;&#x901A;&#x8FC7;&#x54C8;&#x5E0C;&#x8868;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6DFB;&#x52A0;&#xFF0C;&#x5220;&#x9664;&#xFF0C;&#x67E5;&#x627E;&#x7684;&#x590D;&#x6742;&#x5EA6;&#x90FD;&#x662F; O(1)&#x3002;</li>
</ul>
<p>&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sadd</td>
<td>&#x4E3A;&#x96C6;&#x5408;&#x6DFB;&#x52A0;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>smembers</td>
<td>&#x663E;&#x793A;&#x96C6;&#x5408;&#x4E2D;&#x6240;&#x6709;&#x5143;&#x7D20; &#xFF08;&#x65E0;&#x5E8F;&#xFF09;</td>
</tr>
<tr>
<td>scard</td>
<td>&#x8FD4;&#x56DE;&#x96C6;&#x5408;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;</td>
</tr>
<tr>
<td>spop</td>
<td>&#x968F;&#x673A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x5C06;&#x8FD9;&#x4E2A;&#x5143;&#x7D20;&#x5220;&#x9664;</td>
</tr>
<tr>
<td>smove</td>
<td>&#x4ECE;&#x4E00;&#x4E2A;&#x96C6;&#x5408;&#x5411;&#x4EE4;&#x4E00;&#x4E2A;&#x96C6;&#x5408;&#x4E2D;&#x8F6C;&#x79FB;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>srem</td>
<td>&#x4ECE;&#x96C6;&#x5408;&#x4E2D;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>sismember</td>
<td>&#x5224;&#x65AD;&#x96C6;&#x5408;&#x4E2D;&#x662F;&#x5426;&#x5305;&#x542B;&#x8FD9;&#x4E2A;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>srandmember</td>
<td>&#x968F;&#x673A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>sinter</td>
<td>&#x6C42;&#x4EA4;&#x96C6;</td>
</tr>
<tr>
<td>sunion</td>
<td>&#x6C42;&#x548C;&#x96C6;</td>
</tr>
</tbody>
</table>
<h4 id="5zsetsorted-set&#xFF1A;&#x6709;&#x5E8F;&#x96C6;&#x5408;">5.zset(sorted set&#xFF1A;&#x6709;&#x5E8F;&#x96C6;&#x5408;)</h4>
<ul>
<li>Redis zset &#x548C; set &#x4E00;&#x6837;&#x4E5F;&#x662F;string&#x7C7B;&#x578B;&#x5143;&#x7D20;&#x7684;&#x96C6;&#x5408;,&#x4E14;&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x590D;&#x7684;&#x6210;&#x5458;&#x3002;</li>
<li>&#x4E0D;&#x540C;&#x7684;&#x662F;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x90FD;&#x4F1A;&#x5173;&#x8054;&#x4E00;&#x4E2A;double&#x7C7B;&#x578B;&#x7684;&#x5206;&#x6570;&#x3002;redis&#x6B63;&#x662F;&#x901A;&#x8FC7;&#x5206;&#x6570;&#x6765;&#x4E3A;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x6210;&#x5458;&#x8FDB;&#x884C;&#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x7684;&#x6392;&#x5E8F;&#x3002;</li>
<li>zset&#x7684;&#x6210;&#x5458;&#x662F;&#x552F;&#x4E00;&#x7684;,&#x4F46;&#x5206;&#x6570;(score)&#x5374;&#x53EF;&#x4EE5;&#x91CD;&#x590D;&#x3002;</li>
</ul>
<p>&#x64CD;&#x4F5C;&#x6307;&#x4EE4;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>zadd</td>
<td>&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>zcard</td>
<td>&#x8FD4;&#x56DE;&#x96C6;&#x5408;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;</td>
</tr>
<tr>
<td>zrange&#x5347;&#x5E8F; zrevrange&#x964D;&#x5E8F;</td>
<td>&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>zrangebyscore</td>
<td>&#x6309;&#x7167;&#x5206;&#x6570;&#x67E5;&#x627E;&#x4E00;&#x4E2A;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>zrank</td>
<td>&#x8FD4;&#x56DE;&#x6392;&#x540D;</td>
</tr>
<tr>
<td>zrevrank</td>
<td>&#x5012;&#x53D9;&#x6392;&#x540D;</td>
</tr>
<tr>
<td>zscore</td>
<td>&#x663E;&#x793A;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x5206;&#x6570;</td>
</tr>
<tr>
<td>zrem</td>
<td>&#x79FB;&#x9664;&#x67D0;&#x4E2A;&#x5143;&#x7D20;</td>
</tr>
<tr>
<td>zincrby</td>
<td>&#x7ED9;&#x67D0;&#x4E2A;&#x7279;&#x5B9A;&#x5143;&#x7D20;&#x52A0;&#x5206;</td>
</tr>
</tbody>
</table>
<h3 id="springboot&#x64CD;&#x4F5C;redis"><strong>springboot&#x64CD;&#x4F5C;Redis</strong></h3>
<p>spring boot data redis&#x4E2D;&#x63D0;&#x4F9B;&#x4E86;RedisTemplate&#x548C;StringRedisTemplate&#xFF0C;&#x5176;&#x4E2D;StringRedisTemplate&#x662F;Redistemplate&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x57FA;&#x672C;&#x4E00;&#x81F4;&#xFF0C;&#x4E0D;&#x540C;&#x4E4B;&#x5904;&#x4E3B;&#x8981;&#x4F53;&#x73B0;&#x5728;&#x64CD;&#x4F5C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;RedisTemplate&#x4E2D;&#x7684;&#x4E24;&#x4E2A;&#x6CDB;&#x578B;&#x90FD;&#x662F;Object&#xFF0C;&#x610F;&#x5473;&#x7740;&#x5B58;&#x50A8;&#x7684;key&#x548C;value&#x90FD;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;StringRedisTemplate&#x7684;&#x4E24;&#x4E2A;&#x6CDB;&#x578B;&#x90FD;&#x662F;String&#xFF0C;&#x610F;&#x5473;&#x7740;StringRedisTemplate&#x7684;key&#x548C;value&#x90FD;&#x53EA;&#x80FD;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<p>&#x5F15;&#x5165;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<h3 id="springboot-&#x914D;&#x7F6E;redis"><strong>springboot &#x914D;&#x7F6E;redis</strong></h3>
<pre><code class="lang-yaml"><span class="hljs-attr">spring:</span>
<span class="hljs-attr">  redis:</span>
    <span class="hljs-comment"># Redis&#x6570;&#x636E;&#x5E93;&#x7D22;&#x5F15;&#xFF08;&#x9ED8;&#x8BA4;&#x4E3A;0&#xFF09;</span>
<span class="hljs-attr">    database:</span> <span class="hljs-number">0</span>
    <span class="hljs-comment"># Redis&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;</span>
<span class="hljs-attr">    host:</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
    <span class="hljs-comment"># Redis&#x670D;&#x52A1;&#x5668;&#x8FDE;&#x63A5;&#x7AEF;&#x53E3;</span>
<span class="hljs-attr">    port:</span> <span class="hljs-number">6379</span>
    <span class="hljs-comment"># Redis&#x670D;&#x52A1;&#x5668;&#x8FDE;&#x63A5;&#x5BC6;&#x7801;&#xFF08;&#x9ED8;&#x8BA4;&#x4E3A;&#x7A7A;&#xFF09;</span>
<span class="hljs-attr">    password:</span>
    <span class="hljs-comment"># &#x8FDE;&#x63A5;&#x6C60;&#x6700;&#x5927;&#x8FDE;&#x63A5;&#x6570;&#xFF08;&#x4F7F;&#x7528;&#x8D1F;&#x503C;&#x8868;&#x793A;&#x6CA1;&#x6709;&#x9650;&#x5236;&#xFF09;</span>
    jedis.pool.max-active: <span class="hljs-number">20</span>
    <span class="hljs-comment"># &#x8FDE;&#x63A5;&#x6C60;&#x6700;&#x5927;&#x963B;&#x585E;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#xFF08;&#x4F7F;&#x7528;&#x8D1F;&#x503C;&#x8868;&#x793A;&#x6CA1;&#x6709;&#x9650;&#x5236;&#xFF09;</span>
    jedis.pool.max-wait: <span class="hljs-bullet">-1</span>
    <span class="hljs-comment"># &#x8FDE;&#x63A5;&#x6C60;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x7A7A;&#x95F2;&#x8FDE;&#x63A5;</span>
    jedis.pool.max-idle: <span class="hljs-number">10</span>
    <span class="hljs-comment"># &#x8FDE;&#x63A5;&#x6C60;&#x4E2D;&#x7684;&#x6700;&#x5C0F;&#x7A7A;&#x95F2;&#x8FDE;&#x63A5;</span>
    jedis.pool.min-idle: <span class="hljs-number">0</span>
    <span class="hljs-comment"># &#x8FDE;&#x63A5;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#xFF08;&#x6BEB;&#x79D2;&#xFF09;</span>
<span class="hljs-attr">    timeout:</span> <span class="hljs-number">1000</span>
</code></pre>
<h3 id="redistemplate&#x53CA;&#x5176;&#x76F8;&#x5173;&#x65B9;&#x6CD5;">RedisTemplate&#x53CA;&#x5176;&#x76F8;&#x5173;&#x65B9;&#x6CD5;</h3>
<h4 id="1redistemplate">1.RedisTemplate</h4>
<p>Spring&#x5C01;&#x88C5;&#x4E86;RedisTemplate&#x5BF9;&#x8C61;&#x6765;&#x8FDB;&#x884C;&#x5BF9;Redis&#x7684;&#x5404;&#x79CD;&#x64CD;&#x4F5C;&#xFF0C;&#x5B83;&#x652F;&#x6301;&#x6240;&#x6709;&#x7684;Redis&#x539F;&#x751F;&#x7684;api&#x3002;RedisTemplate&#x4F4D;&#x4E8E;spring-data-redis&#x5305;&#x4E0B;&#x3002;RedisTemplate&#x63D0;&#x4F9B;&#x4E86;redis&#x5404;&#x79CD;&#x64CD;&#x4F5C;&#x3001;&#x5F02;&#x5E38;&#x5904;&#x7406;&#x53CA;&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x652F;&#x6301;&#x53D1;&#x5E03;&#x8BA2;&#x9605;&#x3002;</p>
<h4 id="2redis5&#x79CD;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x64CD;&#x4F5C;">2.Redis5&#x79CD;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x64CD;&#x4F5C;</h4>
<ul>
<li>redisTemplate.opsForValue(); //&#x64CD;&#x4F5C;&#x5B57;&#x7B26;&#x4E32;</li>
<li>redisTemplate.opsForHash(); //&#x64CD;&#x4F5C;hash</li>
<li>redisTemplate.opsForList(); //&#x64CD;&#x4F5C;list</li>
<li>redisTemplate.opsForSet(); //&#x64CD;&#x4F5C;set</li>
<li>redisTemplate.opsForZSet(); //&#x64CD;&#x4F5C;&#x6709;&#x5E8F;set</li>
</ul>
<p>&#x6216;&#x8005;&#xFF1A;</p>
<ul>
<li>redistempalate.boundValueOps</li>
<li>redistempalate.boundSetOps</li>
<li>redistempalate.boundListOps</li>
<li>redistempalate.boundHashOps</li>
<li>redistempalate.boundZSetOps</li>
</ul>
<blockquote>
<p>opsForXXX&#x548C;boundXXXOps&#x7684;&#x533A;&#x522B;&#xFF1A;XXX&#x4E3A;value&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x524D;&#x8005;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;operator&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x64CD;&#x4F5C;&#x7684;&#x5BF9;&#x8C61;&#xFF08;key&#xFF09;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x4E00;&#x4E2A;&#x8FDE;&#x63A5;&#xFF08;&#x4E8B;&#x52A1;&#xFF09;&#x5185;&#x64CD;&#x4F5C;&#x591A;&#x4E2A;key&#x4EE5;&#x53CA;&#x5BF9;&#x5E94;&#x7684;value&#xFF1B;&#x540E;&#x8005;&#x83B7;&#x53D6;&#x4E86;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x64CD;&#x4F5C;&#x5BF9;&#x8C61;&#xFF08;key&#xFF09;&#x7684;operator&#xFF0C;&#x5728;&#x4E00;&#x4E2A;&#x8FDE;&#x63A5;&#xFF08;&#x4E8B;&#x52A1;&#xFF09;&#x5185;&#x53EA;&#x80FD;&#x64CD;&#x4F5C;&#x8FD9;&#x4E2A;key&#x5BF9;&#x5E94;&#x7684;value&#x3002;</p>
</blockquote>
<p><strong>SpringBootTest &#x5B9E;&#x73B0;Redis&#x6570;&#x636E;&#x5E93;&#x589E;&#x5220;&#x6539;&#x67E5;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * &#x4F7F;&#x7528;RedisTemplate &#x64CD;&#x4F5C;Redis&#x6570;&#x636E;&#x7684;&#x4E0D;&#x540C;&#x6570;&#x636E;&#x7C7B;&#x578B;
 */</span>
<span class="hljs-meta">@SpringBootTest</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Springbootday03ApplicationTests</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> RedisTemplate&lt;String, String&gt; redisTemplate;

    <span class="hljs-comment">/**
     * String &#x7C7B;&#x578B;&#x6570;&#x636E;&#x64CD;&#x4F5C;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateString</span><span class="hljs-params">()</span> </span>{

        <span class="hljs-comment">//&#x6DFB;&#x52A0;&#x503C;</span>
        redisTemplate.opsForValue().set(<span class="hljs-string">&quot;str&quot;</span>, <span class="hljs-string">&quot;strValue1&quot;</span>);

        <span class="hljs-comment">//&#x6DFB;&#x52A0;&#x503C;  &#x5224;&#x5B9A;&#x662F;&#x5426;&#x5B58;&#x5728; &#x5B58;&#x5728;&#x5219;&#x4E0D;&#x6DFB;&#x52A0;</span>
        Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(<span class="hljs-string">&quot;str&quot;</span>, <span class="hljs-string">&quot;strAbsent&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;str&#x8BBE;&#x7F6E;&#x6210;&#x529F;:&quot;</span> + aBoolean);

        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x503C;</span>
        String str = redisTemplate.opsForValue().get(<span class="hljs-string">&quot;str&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;str = &quot;</span> + str);

        <span class="hljs-comment">//&#x66F4;&#x65B0;&#x503C;</span>
        redisTemplate.opsForValue().set(<span class="hljs-string">&quot;str&quot;</span>, <span class="hljs-string">&quot;strValue2&quot;</span>);
        str = redisTemplate.opsForValue().get(<span class="hljs-string">&quot;str&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;newStr = &quot;</span> + str);

        <span class="hljs-comment">//&#x5220;&#x9664;&#x503C;</span>
        Boolean b = redisTemplate.delete(<span class="hljs-string">&quot;str&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;str&#x5220;&#x9664;&#x6210;&#x529F;&#xFF1A;&quot;</span> + b);

    }

    <span class="hljs-comment">/**
     * &#x64CD;&#x4F5C;string&#x7C7B;&#x578B;&#x6570;&#x636E;  &#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateString2</span><span class="hljs-params">()</span> </span>{
        redisTemplate.opsForValue().set(<span class="hljs-string">&quot;str&quot;</span>, <span class="hljs-string">&quot;strTimeout&quot;</span>, <span class="hljs-number">10</span>, TimeUnit.SECONDS);
        <span class="hljs-comment">//&#x5224;&#x5B9A;&#x503C;&#x662F;&#x5426;&#x5B58;&#x5728; &#x4E0D;&#x5B58;&#x5728;&#x5219;&#x8BBE;&#x7F6E;&#x503C; &#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;</span>
        Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(<span class="hljs-string">&quot;str2&quot;</span>, <span class="hljs-string">&quot;strTimeoutAbsent&quot;</span>, <span class="hljs-number">20</span>, TimeUnit.SECONDS);
        System.out.println(<span class="hljs-string">&quot;setIfAbsent:&quot;</span> + aBoolean);
    }

    <span class="hljs-comment">/**
     * &#x64CD;&#x4F5C;hash&#x7C7B;&#x578B;&#x6570;&#x636E;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateHash</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">//&#x6DFB;&#x52A0;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  key - value</span>
        redisTemplate.opsForHash().put(<span class="hljs-string">&quot;hash&quot;</span>, <span class="hljs-string">&quot;username&quot;</span>, <span class="hljs-string">&quot;admin&quot;</span>);
        <span class="hljs-comment">//&#x4FEE;&#x6539;hash&#x7C7B;&#x578B;&#x6570;&#x636E;</span>
        redisTemplate.opsForHash().put(<span class="hljs-string">&quot;hash&quot;</span>, <span class="hljs-string">&quot;username&quot;</span>, <span class="hljs-string">&quot;tom&quot;</span>);
        redisTemplate.opsForHash().put(<span class="hljs-string">&quot;hash&quot;</span>, <span class="hljs-string">&quot;password&quot;</span>, <span class="hljs-string">&quot;123456&quot;</span>);

        <span class="hljs-comment">//&#x6DFB;&#x52A0;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  key - map</span>
        HashMap&lt;String, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
        map.put(<span class="hljs-string">&quot;driverName&quot;</span>, <span class="hljs-string">&quot;com.mysql.jdbc.Driver&quot;</span>);
        map.put(<span class="hljs-string">&quot;url&quot;</span>, <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&quot;</span>);
        redisTemplate.opsForHash().putAll(<span class="hljs-string">&quot;hash&quot;</span>, map);

        <span class="hljs-comment">//&#x83B7;&#x53D6;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  entries</span>
        Map&lt;Object, Object&gt; hash = redisTemplate.opsForHash().entries(<span class="hljs-string">&quot;hash&quot;</span>);
        hash.forEach((key, value) -&gt; {
            System.out.println(key + <span class="hljs-string">&quot;::&quot;</span> + value);
        });

        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;key</span>
        Set&lt;Object&gt; keys = redisTemplate.opsForHash().keys(<span class="hljs-string">&quot;hash&quot;</span>);
        <span class="hljs-keyword">for</span> (Object key : keys) {
            System.out.println(<span class="hljs-string">&quot;key:&quot;</span> + key);
        }
        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x6240;&#x6709;value</span>
        List&lt;Object&gt; values = redisTemplate.opsForHash().values(<span class="hljs-string">&quot;hash&quot;</span>);
        values.forEach(value -&gt; System.out.println(<span class="hljs-string">&quot;value:&quot;</span> + value));

        <span class="hljs-comment">//&#x5220;&#x9664;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  &#x5220;&#x9664;&#x4E00;&#x4E2A;  &#x8FD4;&#x56DE;&#x5220;&#x9664;&#x7684;&#x4E2A;&#x6570;</span>
        Long delete = redisTemplate.opsForHash().delete(<span class="hljs-string">&quot;hash&quot;</span>, <span class="hljs-string">&quot;username&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;delete = &quot;</span> + delete);

        <span class="hljs-comment">//&#x5220;&#x9664;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  &#x5220;&#x9664;&#x591A;&#x4E2A;  &#x8FD4;&#x56DE;&#x5220;&#x9664;&#x7684;&#x4E2A;&#x6570;</span>
        delete = redisTemplate.opsForHash().delete(<span class="hljs-string">&quot;hash&quot;</span>, <span class="hljs-string">&quot;username&quot;</span>, <span class="hljs-string">&quot;password&quot;</span>, <span class="hljs-string">&quot;driverName&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;delete = &quot;</span> + delete);

        <span class="hljs-comment">//&#x5220;&#x9664;hash&#x7C7B;&#x578B;&#x6570;&#x636E;  &#x5220;&#x9664;&#x6240;&#x6709;</span>
        Boolean delHash = redisTemplate.delete(<span class="hljs-string">&quot;hash&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;delHah:&quot;</span> + delHash);

    }

    <span class="hljs-comment">/**
     * &#x64CD;&#x4F5C;List&#x7C7B;&#x578B;  &#x6709;&#x5E8F; &#x53EF;&#x91CD;&#x590D;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateList</span><span class="hljs-params">()</span> </span>{

        <span class="hljs-comment">//&#x5DE6;&#x538B;&#x6808;</span>
        <span class="hljs-comment">// redisTemplate.opsForList().leftPush(&quot;list&quot;, &quot;listValue1&quot;);</span>
        <span class="hljs-comment">// redisTemplate.opsForList().leftPush(&quot;list&quot;, &quot;listValue1&quot;);</span>
        <span class="hljs-comment">// redisTemplate.opsForList().leftPush(&quot;list&quot;, &quot;listValue2&quot;);</span>
        <span class="hljs-comment">// redisTemplate.opsForList().leftPush(&quot;list&quot;, &quot;listValue3&quot;);</span>

        <span class="hljs-comment">//&#x53F3;&#x538B;&#x6808;</span>
        redisTemplate.opsForList().rightPush(<span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-string">&quot;listValue0&quot;</span>);
        redisTemplate.opsForList().rightPush(<span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-string">&quot;listValue2&quot;</span>);
        redisTemplate.opsForList().rightPush(<span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-string">&quot;listValue0&quot;</span>);

        <span class="hljs-comment">//&#x5DE6;&#x51FA;&#x6808;</span>
        String list1 = redisTemplate.opsForList().leftPop(<span class="hljs-string">&quot;list&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;leftPop list1 = &quot;</span> + list1);
        <span class="hljs-comment">//&#x53F3;&#x51FA;&#x6808;</span>
        String list2 = redisTemplate.opsForList().rightPop(<span class="hljs-string">&quot;list&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;rightPop list2 = &quot;</span> + list2);

        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x6240;&#x6709;&#x6570;&#x636E;</span>
        List&lt;String&gt; lists = redisTemplate.opsForList().range(<span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-number">0</span>,                 redisTemplate.opsForList().size(<span class="hljs-string">&quot;list&quot;</span>) - <span class="hljs-number">1</span>);
        lists.forEach(list -&gt; System.out.println(list));


        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x7684;&#x6570;&#x636E;</span>
        redisTemplate.opsForList().set(<span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-number">0</span>, <span class="hljs-string">&quot;listValue0&quot;</span>);
        <span class="hljs-comment">/**
         * &#x4ECE;&#x5B58;&#x50A8;&#x5728;&#x952E;&#x4E2D;&#x7684;&#x5217;&#x8868;&#x4E2D;&#x5220;&#x9664;&#x7B49;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x8BA1;&#x6570;&#x4E8B;&#x4EF6;&#x3002;
         * count&gt; 0&#xFF1A;&#x5220;&#x9664;&#x7B49;&#x4E8E;&#x4ECE;&#x5DE6;&#x5230;&#x53F3;&#x79FB;&#x52A8;&#x7684;&#x503C;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF1B;
         * count&lt; 0&#xFF1A;&#x5220;&#x9664;&#x7B49;&#x4E8E;&#x4ECE;&#x53F3;&#x5230;&#x5DE6;&#x79FB;&#x52A8;&#x7684;&#x503C;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF1B;
         * count = 0&#xFF1A;&#x5220;&#x9664;&#x7B49;&#x4E8E;value&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#x3002;
         */</span>
        Long remove = redisTemplate.opsForList().remove(<span class="hljs-string">&quot;list&quot;</span>, -<span class="hljs-number">1</span>, <span class="hljs-string">&quot;listValue0&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;remove:&quot;</span> + remove);

        <span class="hljs-comment">//&#x5220;&#x9664;&#x6307;&#x5B9A;key&#x7684;list&#x6570;&#x636E;</span>
        Boolean list = redisTemplate.delete(<span class="hljs-string">&quot;list&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;list&#x96C6;&#x5408;&#x5220;&#x9664;&#x6210;&#x529F;:&quot;</span> + list);
    }

    <span class="hljs-comment">/**
     * &#x64CD;&#x4F5C;Set&#x7C7B;&#x578B;  &#x65E0;&#x5E8F; &#x4E0D;&#x53EF;&#x91CD;&#x590D;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateSet</span><span class="hljs-params">()</span> </span>{

        <span class="hljs-comment">//&#x8BBE;&#x7F6E;set&#x503C;</span>
        redisTemplate.opsForSet().add(<span class="hljs-string">&quot;set&quot;</span>, <span class="hljs-string">&quot;setValue0&quot;</span>);
        redisTemplate.opsForSet().add(<span class="hljs-string">&quot;set&quot;</span>, <span class="hljs-string">&quot;setValue0&quot;</span>);
        redisTemplate.opsForSet().add(<span class="hljs-string">&quot;set&quot;</span>, <span class="hljs-string">&quot;setValue1&quot;</span>);

        <span class="hljs-comment">//&#x5224;&#x5B9A;&#x662F;&#x5426;&#x5305;&#x542B;</span>
        Boolean member = redisTemplate.opsForSet().isMember(<span class="hljs-string">&quot;set&quot;</span>, <span class="hljs-string">&quot;setValue0&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;isMember:&quot;</span> + member);

        <span class="hljs-comment">//&#x5220;&#x9664;set&#x4E2D;&#x7684;&#x503C;</span>
        Long remove = redisTemplate.opsForSet().remove(<span class="hljs-string">&quot;set&quot;</span>, <span class="hljs-string">&quot;setValue0&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;remove = &quot;</span> + remove);

        <span class="hljs-comment">//&#x83B7;&#x53D6;set&#x7C7B;&#x578B;&#x503C;</span>
        Set&lt;String&gt; set = redisTemplate.opsForSet().members(<span class="hljs-string">&quot;set&quot;</span>);
        set.forEach(str -&gt; {
            System.out.println(<span class="hljs-string">&quot;str = &quot;</span> + str);
        });
    }

    <span class="hljs-comment">/**
     * &#x64CD;&#x4F5C; ZSet  &#x6709;&#x5E8F; &#x4E0D;&#x53EF;&#x91CD;&#x590D;
     */</span>
    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">operateZSet</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">//&#x5B58;&#x50A8;&#x503C;</span>
        Boolean add = redisTemplate.opsForZSet().add(<span class="hljs-string">&quot;zset&quot;</span>, <span class="hljs-string">&quot;zsetValue0&quot;</span>, <span class="hljs-number">10</span>);
        System.out.println(<span class="hljs-string">&quot;add = &quot;</span> + add);
        System.out.println(<span class="hljs-string">&quot;add = &quot;</span> + add);
        add = redisTemplate.opsForZSet().add(<span class="hljs-string">&quot;zset&quot;</span>, <span class="hljs-string">&quot;zsetValue2&quot;</span>, <span class="hljs-number">2</span>);
        System.out.println(<span class="hljs-string">&quot;add = &quot;</span> + add);
        <span class="hljs-comment">//&#x83B7;&#x53D6;&#x503C;</span>
        <span class="hljs-comment">// Boolean zset = redisTemplate.delete(&quot;zset&quot;);</span>
        <span class="hljs-comment">// System.out.println(&quot;delete zset = &quot; + zset);</span>
    }
}
</code></pre>
<p><strong>Redis&#x5DE5;&#x5177;&#x7C7B;&#x7684;&#x5C01;&#x88C5;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * Redis &#x5DE5;&#x5177;&#x7C7B;
 * <span class="hljs-doctag">@author</span> mosin
 * date 2021/11/30
 * <span class="hljs-doctag">@version</span> 1.0
 */</span>
<span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RedisUtil</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-title">RedisUtil</span><span class="hljs-params">()</span></span>{};
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> RedisTemplate&lt;String,String&gt; redisTemplate;

    <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x503C;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">setValue</span><span class="hljs-params">(String key,String value)</span></span>{
        redisTemplate.opsForValue().set(key, value);
    }
    <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x503C; &#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x6709;&#x6548;&#x65F6;&#x95F4;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setValue</span><span class="hljs-params">(String key, String value, Long timeOut, TimeUnit timeUnit)</span></span>{
        redisTemplate.opsForValue().setIfAbsent(key, value, timeOut, timeUnit);
    }

    <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x503C; &#x6CA1;&#x6709;&#x5219;&#x8BBE;&#x7F6E; &#x6709;&#x5219;&#x4E0D;&#x8BBE;&#x7F6E;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">setNx</span><span class="hljs-params">(String key,String value)</span></span>{
        redisTemplate.opsForValue().setIfAbsent(key, value);
    }

    <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x503C; &#x6CA1;&#x6709;&#x5219;&#x8BBE;&#x7F6E; &#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x6709;&#x6548;&#x65F6;&#x95F4; &#x6709;&#x5219;&#x4E0D;&#x8BBE;&#x7F6E;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">setNx</span><span class="hljs-params">(String key,String value,<span class="hljs-keyword">long</span> timeOut,TimeUnit timeUnit)</span></span>{
        redisTemplate.opsForValue().setIfAbsent(key, value,timeOut,timeUnit);
    }

    <span class="hljs-comment">//&#x5220;&#x9664;&#x503C;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">del</span><span class="hljs-params">(String key)</span></span>{
        <span class="hljs-keyword">return</span> redisTemplate.delete(key);
    }

     <span class="hljs-comment">//&#x83B7;&#x53D6;&#x503C;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getValue</span><span class="hljs-params">(String key)</span></span>{
        <span class="hljs-keyword">return</span>  redisTemplate.opsForValue().get(key);
    }
}
</code></pre>
<p><strong>&#x4E1A;&#x52A1;&#x5B9E;&#x8DF5;</strong>&#xFF08;redis&#x5B58;&#x50A8;token&#xFF0C;&#x5B9E;&#x73B0;&#x975E;&#x6CD5;&#x8BF7;&#x6C42;&#x62E6;&#x622A;&#xFF09;</p>
<p>1.&#x7F16;&#x5199;&#x62E6;&#x622A;&#x5668;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AdminInterceptor</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">HandlerInterceptor</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> RedisUtil redisUtil;
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">preHandle</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response, Object handler)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        System.out.println(<span class="hljs-string">&quot;&#x62E6;&#x622A;&#x5668;&#x4EE5;&#x62E6;&#x622A;&#x8BF7;&#x6C42;&quot;</span>);
        <span class="hljs-comment">//&#x4ECE;&#x8BF7;&#x6C42;&#x5934;&#x4E2D;&#x83B7;&#x53D6;token  &#x9A8C;&#x8BC1;&#x7528;&#x6237;&#x662F;&#x5426;&#x767B;&#x5F55;</span>
        String token = request.getHeader(<span class="hljs-string">&quot;token&quot;</span>);
        System.out.println(token);
        String tokenValue = redisUtil.getValue(token);
        System.out.println(<span class="hljs-string">&quot;tokenValue = &quot;</span> + tokenValue);
        <span class="hljs-keyword">if</span>(tokenValue!=<span class="hljs-keyword">null</span>){ <span class="hljs-comment">//&#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55; &#x653E;&#x884C;&#x8BF7;&#x6C42;</span>
            <span class="hljs-keyword">return</span>  <span class="hljs-keyword">true</span>;
        }<span class="hljs-keyword">else</span>{<span class="hljs-comment">//&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x767B;&#x5F55;&#x9875;&#x9762;</span>
            response.sendRedirect(request.getContextPath()+<span class="hljs-string">&quot;/login.jsp&quot;</span>);
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
        }
    }
}
</code></pre>
<p>2.&#x914D;&#x7F6E;&#x62E6;&#x622A;&#x5668;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LoginConfig</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">WebMvcConfigurer</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> AdminInterceptor adminInterceptor;
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">addInterceptors</span><span class="hljs-params">(InterceptorRegistry registry)</span> </span>{
        InterceptorRegistration registration = registry.addInterceptor(adminInterceptor);
        registration.addPathPatterns(<span class="hljs-string">&quot;/**&quot;</span>);
        registration.excludePathPatterns(<span class="hljs-string">&quot;/user/login&quot;</span>,<span class="hljs-string">&quot;/user/register&quot;</span>,<span class="hljs-string">&quot;/login.jsp&quot;</span>);
    }
}
</code></pre>
<p>3.&#x7F16;&#x5199;&#x7EDF;&#x4E00;&#x8FD4;&#x56DE;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Data</span>
<span class="hljs-meta">@AllArgsConstructor</span>
<span class="hljs-meta">@NoArgsConstructor</span>
<span class="hljs-meta">@Builder</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JsonResult</span>&lt;<span class="hljs-title">T</span>&gt; </span>{
    <span class="hljs-keyword">private</span> Integer code;
    <span class="hljs-keyword">private</span> String msg;
    <span class="hljs-keyword">private</span> Long count;
    <span class="hljs-keyword">private</span> T data;
}
</code></pre>
<p>4.&#x7F16;&#x5199;&#x63A7;&#x5236;&#x5668;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/user&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserController</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> UserService userService;
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> RedisUtil redisUtil;
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/login&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">login</span><span class="hljs-params">(User user)</span> <span class="hljs-keyword">throws</span> JsonProcessingException </span>{
        User usr = User.builder().id(<span class="hljs-number">1</span>).name(<span class="hljs-string">&quot;admin&quot;</span>).password(<span class="hljs-string">&quot;123456&quot;</span>).build();
        <span class="hljs-comment">//&#x83B7;&#x53D6;token  &#x653E;&#x5165;redis</span>
        String token = UUID.randomUUID().toString().replace(<span class="hljs-string">&quot;-&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
        <span class="hljs-comment">//&#x5C06;user &#x8F6C;&#x4E3A;json&#x683C;&#x5F0F;&#x653E;&#x5165; redis</span>
        ObjectMapper objectMapper = <span class="hljs-keyword">new</span> ObjectMapper();
        String s1 = objectMapper.writeValueAsString(usr);
        <span class="hljs-comment">//&#x5C06; token &#x548C;&#x7528;&#x6237;&#x4FE1;&#x606F;&#x5B58;&#x5165; redis</span>
        redisUtil.setValue(token, s1, <span class="hljs-number">2L</span>, TimeUnit.MINUTES);
        <span class="hljs-comment">//&#x5C06;token &#x5B58;&#x5165;map&#x96C6;&#x5408;&#x8FD4;&#x56DE;</span>
        HashMap&lt;String, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
        map.put(<span class="hljs-string">&quot;token&quot;</span>, token);
        <span class="hljs-keyword">return</span> map;
    }

    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/register&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">register</span><span class="hljs-params">(User user)</span></span>{
        HashMap&lt;String, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
        map.put(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;ok&quot;</span>);
        <span class="hljs-keyword">return</span> map;
    }

    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/add&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">add</span><span class="hljs-params">(User user)</span></span>{
        HashMap&lt;String, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
        map.put(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;ok&quot;</span>);
        <span class="hljs-keyword">return</span> map;
    }
}
</code></pre>
<p>5.&#x7F16;&#x5199;&#x4E1A;&#x52A1;&#x7C7B;&#x548C;Mapper&#x63A5;&#x53E3;</p>
<p>6.&#x4F7F;&#x7528;postman&#x63A5;&#x53E3;&#x6D4B;&#x8BD5;&#x5DE5;&#x5177;&#x6D4B;&#x8BD5;&#x63A5;&#x53E3;</p>
<h2 id="springboot&#x5B9E;&#x73B0;&#x4E0A;&#x4F20;&#x4E0B;&#x8F7D;">springBoot&#x5B9E;&#x73B0;&#x4E0A;&#x4F20;&#x4E0B;&#x8F7D;</h2>
<p>1.&#x7F16;&#x5199;&#x63A7;&#x5236;&#x5668;</p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * &#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x4E0B;&#x8F7D;&#x63A7;&#x5236;&#x7C7B;
 * <span class="hljs-doctag">@author</span> mosin
 * date 2021/12/1
 * <span class="hljs-doctag">@version</span> 1.0
 */</span>
<span class="hljs-meta">@Controller</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/file&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FileController</span> </span>{

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/toupload&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">toUpload</span><span class="hljs-params">()</span></span>{ <span class="hljs-comment">//&#x8DF3;&#x8F6C;&#x4E0A;&#x4F20;&#x9875;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;upload&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/upload&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">fileUpload</span><span class="hljs-params">(MultipartFile file, Model model)</span></span>{
        <span class="hljs-keyword">if</span>( !file.isEmpty()){
            String originalFilename = file.getOriginalFilename();
            String uuid = UUID.randomUUID().toString().replace(<span class="hljs-string">&quot;-&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
            String suffix = originalFilename.substring(originalFilename.lastIndexOf(<span class="hljs-string">&quot;.&quot;</span>));
            String fileName = uuid+suffix;
            File f = <span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;D:\\upload&quot;</span>,fileName);
            <span class="hljs-keyword">try</span> {
                file.transferTo(f);
                model.addAttribute(<span class="hljs-string">&quot;downloadName&quot;</span>, fileName);
                model.addAttribute(<span class="hljs-string">&quot;originalFilename&quot;</span>, originalFilename);
            } <span class="hljs-keyword">catch</span> (IOException e) {
                e.printStackTrace();
            }
        }
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;download&quot;</span>;
    }

    <span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/download&quot;</span>)
    <span class="hljs-meta">@ResponseBody</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">fileDownLoad</span><span class="hljs-params">(String fileName, HttpServletResponse response)</span></span>{
        HashMap&lt;String, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
        <span class="hljs-keyword">try</span> {
            FileInputStream fis= <span class="hljs-keyword">new</span> FileInputStream(<span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;D:\\upload&quot;</span>, fileName));
            <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x4EE5;&#x9644;&#x4EF6;&#x5F62;&#x5F0F;&#x8F93;&#x51FA;</span>
           response.setHeader(<span class="hljs-string">&quot;Content-disposition&quot;</span>, <span class="hljs-string">&quot;attachment; filename=&quot;</span>+fileName);
            <span class="hljs-comment">//&#x83B7;&#x53D6;&#x8F93;&#x51FA;&#x6D41;</span>
            ServletOutputStream outputStream = response.getOutputStream();
            <span class="hljs-comment">//org.springframework.util.FileCopyUtils  &#x5DE5;&#x5177;&#x7C7B;</span>
            FileCopyUtils.copy(fis, outputStream);
            map.put(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;&#x4E0A;&#x4F20;&#x6210;&#x529F;!&quot;</span>);
        } <span class="hljs-keyword">catch</span> (Exception e) {
            e.printStackTrace();
            map.put(<span class="hljs-string">&quot;msg&quot;</span>, <span class="hljs-string">&quot;&#x4E0A;&#x4F20;&#x5931;&#x8D25;!&quot;</span>);
        }
        <span class="hljs-keyword">return</span> map ;
    }
}
</code></pre>
<p>2.&#x7F16;&#x5199;&#x4E0A;&#x4F20;&#x9875;&#x9762;</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span> <span class="hljs-attr">xmlns:th</span>=<span class="hljs-string">&quot;http://www.thmeleaf.org&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>&#x6587;&#x4EF6;&#x4E0A;&#x4F20;<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">th:action</span>=<span class="hljs-string">&quot;@{/file/upload}&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span> <span class="hljs-attr">enctype</span>=<span class="hljs-string">&quot;multipart/form-data&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;file&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;file&quot;</span> &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x4E0A;&#x4F20;&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>3.&#x7F16;&#x5199;&#x4E0B;&#x8F7D;&#x9875;&#x9762;</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span> <span class="hljs-attr">xmlns:th</span>=<span class="hljs-string">&quot;http://www.thymeleaf.org&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>&#x4E0B;&#x8F7D;&#x9875;&#x9762;<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>&#x4E0B;&#x8F7D;&#x5217;&#x8868;<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:href</span>=<span class="hljs-string">&quot;@{/file/download(fileName=${downloadName})}&quot;</span><span class="hljs-string">+</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;${originalFilename}&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><strong>&#x8BBE;&#x7F6E;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#x5927;&#x5C0F;&#x9650;&#x5236;</strong></p>
<pre><code class="lang-yaml"><span class="hljs-attr">spring:</span>
<span class="hljs-attr">  servlet:</span>
<span class="hljs-attr">    multipart:</span>
<span class="hljs-attr">      enabled:</span> <span class="hljs-literal">true</span> <span class="hljs-comment">#&#x542F;&#x7528;http&#x4E0A;&#x4F20;&#x5904;&#x7406;</span>
<span class="hljs-attr">      max-file-size:</span> <span class="hljs-number">20</span>MB <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x5355;&#x4E2A;&#x6587;&#x4EF6;&#x5927;&#x5C0F;&#x9650;&#x5236;</span>
<span class="hljs-attr">      max-request-size:</span> <span class="hljs-number">100</span>MB <span class="hljs-comment">#&#x6700;&#x5927;&#x8BF7;&#x6C42;&#x6587;&#x4EF6;&#x5927;&#x5C0F;</span>
<span class="hljs-attr">      file-size-threshold:</span> <span class="hljs-number">10</span>MB <span class="hljs-comment">#&#x5F53;&#x6587;&#x4EF6;&#x8FBE;&#x5230;&#x591A;&#x5C11;&#x65F6;&#x5199;&#x5165;&#x78C1;&#x76D8;</span>
</code></pre>
<h2 id="springboot-cors&#xFF08;&#x8DE8;&#x57DF;&#x8D44;&#x6E90;&#x5171;&#x4EAB;&#xFF09;">springBoot CORS&#xFF08;&#x8DE8;&#x57DF;&#x8D44;&#x6E90;&#x5171;&#x4EAB;&#xFF09;</h2>
<p>CORS&#x662F;&#x4E00;&#x4E2A;W3C&#x6807;&#x51C6;&#xFF0C;&#x5168;&#x79F0;&#x662F;&quot;&#x8DE8;&#x57DF;&#x8D44;&#x6E90;&#x5171;&#x4EAB;&quot;&#xFF08;Cross-origin resource sharing&#xFF09;&#x3002;&#x5B83;&#x5141;&#x8BB8;&#x6D4F;&#x89C8;&#x5668;&#x5411;&#x8DE8;&#x6E90;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x53D1;&#x51FA;<a href="https://www.ruanyifeng.com/blog/2012/09/xmlhttprequest_level_2.html" target="_blank"><code>XMLHttpRequest</code></a>&#x8BF7;&#x6C42;&#xFF0C;&#x4ECE;&#x800C;&#x514B;&#x670D;&#x4E86;AJAX&#x53EA;&#x80FD;&#x540C;&#x6E90;&#x4F7F;&#x7528;&#x7684;&#x9650;&#x5236;&#x3002;</p>
<p><strong>&#x4EC0;&#x4E48;&#x662F;&#x540C;&#x6E90;&#x7B56;&#x7565;&#xFF1F;</strong>
&#x540C;&#x6E90;&#x7B56;&#x7565;&#x662F;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E00;&#x4E2A;&#x5B89;&#x5168;&#x529F;&#x80FD;&#xFF0C;&#x4E0D;&#x540C;&#x6E90;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x811A;&#x672C;&#x5728;&#x6CA1;&#x6709;&#x660E;&#x786E;&#x6388;&#x6743;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E0D;&#x80FD;&#x8BFB;&#x5199;&#x5BF9;&#x65B9;&#x8D44;&#x6E90;&#x3002;&#x6240;&#x4EE5;a.com&#x4E0B;&#x7684;js&#x811A;&#x672C;&#x91C7;&#x7528;ajax&#x8BFB;&#x53D6;b.com&#x91CC;&#x9762;&#x7684;&#x6587;&#x4EF6;&#x6570;&#x636E;&#x662F;&#x4F1A;&#x62A5;&#x9519;&#x7684;&#x3002;</p>
<p>&#x5148;&#x6765;&#x8BF4;&#x8BF4;&#x4EC0;&#x4E48;&#x662F;&#x6E90;
&#x2022; &#x6E90;&#xFF08;origin&#xFF09;&#x5C31;&#x662F;&#x534F;&#x8BAE;&#x3001;&#x57DF;&#x540D;&#x548C;&#x7AEF;&#x53E3;&#x53F7;&#x3002;
&#x82E5;&#x5730;&#x5740;&#x91CC;&#x9762;&#x7684;&#x534F;&#x8BAE;&#x3001;&#x57DF;&#x540D;&#x548C;&#x7AEF;&#x53E3;&#x53F7;&#x5747;&#x76F8;&#x540C;&#x5219;&#x5C5E;&#x4E8E;&#x540C;&#x6E90;&#x3002;
&#x4EE5;&#x4E0B;&#x662F;&#x76F8;&#x5BF9;&#x4E8E; <code>http:// www.a.com/test/index.html</code>  &#x7684;&#x540C;&#x6E90;&#x68C0;&#x6D4B;
 <code>http://www.a.com/dir/page.html</code> ----&#x6210;&#x529F;
  <code>http://www.child.a.com/test/index.html</code> ----&#x5931;&#x8D25;&#xFF0C;&#x57DF;&#x540D;&#x4E0D;&#x540C;
  <code>https://www.a.com/test/index.html</code> ----&#x5931;&#x8D25;&#xFF0C;&#x534F;&#x8BAE;&#x4E0D;&#x540C;
 <code>http://www.a.com:8080/test/index.html</code> ----&#x5931;&#x8D25;&#xFF0C;&#x7AEF;&#x53E3;&#x53F7;&#x4E0D;&#x540C;</p>
<p><strong>&#x54EA;&#x4E9B;&#x64CD;&#x4F5C;&#x4E0D;&#x53D7;&#x540C;&#x6E90;&#x9650;&#x5236;</strong></p>
<p>1.script</p>
<p>2.link</p>
<p>3.img</p>
<p>4.form</p>
<p>5.a</p>
<p><strong>&#x54EA;&#x4E9B;&#x64CD;&#x4F5C;&#x53D7;&#x540C;&#x6E90;&#x7684;&#x9650;&#x5236;</strong></p>
<p>1.ajax</p>
<p><strong>&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF1A;</strong></p>
<p>1.&#x5C40;&#x90E8;&#x89E3;&#x51B3;&#x8DE8;&#x57DF;</p>
<ul>
<li>&#x4F7F;&#x7528;&#x6CE8;&#x89E3;@CrossOrigin&#xFF08;&#x5C40;&#x90E8;&#x8DE8;&#x57DF;&#xFF09;</li>
</ul>
<p>2.&#x5168;&#x5C40;&#x89E3;&#x51B3;&#x8DE8;&#x57DF;</p>
<ul>
<li>&#x914D;&#x7F6E;&#x7C7B;&#x89E3;&#x51B3;&#x8DE8;&#x57DF;&#xFF08;&#x5168;&#x5C40;&#x8DE8;&#x57DF;&#xFF09;</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.springframework.context.annotation.Bean;
<span class="hljs-keyword">import</span> org.springframework.context.annotation.Configuration;
<span class="hljs-keyword">import</span> org.springframework.web.cors.CorsConfiguration;
<span class="hljs-keyword">import</span> org.springframework.web.cors.UrlBasedCorsConfigurationSource;
<span class="hljs-keyword">import</span> org.springframework.web.filter.CorsFilter;

<span class="hljs-keyword">import</span> java.util.ArrayList;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CorsConfig</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">private</span> CorsConfiguration <span class="hljs-title">buildConfig</span><span class="hljs-params">()</span> </span>{
        CorsConfiguration corsConfiguration = <span class="hljs-keyword">new</span> CorsConfiguration();
        corsConfiguration.setAllowCredentials(<span class="hljs-keyword">true</span>); <span class="hljs-comment">//sessionid &#x591A;&#x6B21;&#x8BBF;&#x95EE;&#x4E00;&#x81F4;</span>
        <span class="hljs-comment">// &#x5141;&#x8BB8;&#x8BBF;&#x95EE;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x57DF;&#x540D;</span>
        List&lt;String&gt; allowedOriginPatterns = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
        allowedOriginPatterns.add(<span class="hljs-string">&quot;*&quot;</span>);
        corsConfiguration.setAllowedOriginPatterns(allowedOriginPatterns);
        corsConfiguration.addAllowedHeader(<span class="hljs-string">&quot;*&quot;</span>); <span class="hljs-comment">// &#x5141;&#x8BB8;&#x4EFB;&#x4F55;&#x5934;</span>
        corsConfiguration.addAllowedMethod(<span class="hljs-string">&quot;*&quot;</span>); <span class="hljs-comment">// &#x5141;&#x8BB8;&#x4EFB;&#x4F55;&#x65B9;&#x6CD5;&#xFF08;post&#x3001;get&#x7B49;&#xFF09;</span>
        <span class="hljs-keyword">return</span> corsConfiguration;
    }
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CorsFilter <span class="hljs-title">corsFilter</span><span class="hljs-params">()</span> </span>{
        UrlBasedCorsConfigurationSource source = <span class="hljs-keyword">new</span> UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration(<span class="hljs-string">&quot;/**&quot;</span>, buildConfig()); <span class="hljs-comment">// &#x5BF9;&#x63A5;&#x53E3;&#x914D;&#x7F6E;&#x8DE8;&#x57DF;&#x8BBE;&#x7F6E;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> CorsFilter(source);
    }
}


&#x65B9;&#x5F0F;<span class="hljs-number">2</span>&#xFF1A;

<span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyWebMvcConfig</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">WebMvcConfigurer</span> </span>{
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">addCorsMappings</span><span class="hljs-params">(CorsRegistry registry)</span> </span>{
        registry.addMapping(<span class="hljs-string">&quot;/**&quot;</span>)
                .allowedOrigins(<span class="hljs-string">&quot;*&quot;</span>)
                .allowedMethods(<span class="hljs-string">&quot;*&quot;</span>)
                .allowedHeaders(<span class="hljs-string">&quot;*&quot;</span>);
    }
}
</code></pre>
<h2 id="springboot&#x805A;&#x5408;&#x5DE5;&#x7A0B;">springBoot&#x805A;&#x5408;&#x5DE5;&#x7A0B;</h2>
<p><strong>&#x591A;&#x6A21;&#x5757;&#x805A;&#x5408;&#x5DE5;&#x7A0B;&#xFF1A;&#x6309;&#x7167;MVC&#x7684;&#x601D;&#x60F3;&#xFF0C;&#x5C06;&#x5E94;&#x7528;&#x5206;&#x6210;&#x4E09;&#x5C42;web&#x3001;service&#x3001;mapper/dao&#x8FD9;&#x4E09;&#x4E2A;&#x4E3B;&#x8981;&#x6A21;&#x5757;&#xFF0C;&#x5728;&#x5B9E;&#x9645;&#x7684;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x4E2D;&#x53EF;&#x80FD;&#x4F1A;&#x6839;&#x636E;&#x5B9E;&#x9645;&#x7684;&#x4E1A;&#x52A1;&#x5C06;&#x805A;&#x5408;&#x5DE5;&#x7A0B;&#x5206;&#x6210;&#x5982;&#x4E0B;&#x7684;&#x5F62;&#x5F0F;:</strong></p>
<ol>
<li>common&#xFF1A;&#x901A;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x6A21;&#x5757;&#xFF0C;&#x4E13;&#x95E8;&#x7528;&#x4E8E;&#x9879;&#x76EE;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x4E00;&#x4E9B;&#x5DE5;&#x5177;&#x7C7B;&#x3002;</li>
<li>entity&#xFF1A;&#x5B9E;&#x4F53;&#x7C7B;&#x6A21;&#x5757;&#xFF0C;&#x4E13;&#x95E8;&#x5B58;&#x653E;&#x5B9E;&#x4F53;&#x7C7B;&#x5BF9;&#x8C61;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;DTO&#x3001;BO&#x3001;AO&#x3001;VO&#x7B49;&#x7B49;&#x5BF9;&#x8C61;&#x3002;</li>
<li>mapper&#xFF1A;dao&#x63A5;&#x53E3;&#x6A21;&#x5757;&#xFF0C;&#x4E13;&#x95E8;&#x5B58;&#x653E;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#x7684;dao&#x63A5;&#x53E3;&#x3002;</li>
<li>service&#xFF1A;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x6A21;&#x5757;&#xFF0C;&#x4E13;&#x95E8;&#x8FDB;&#x884C;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x7684;&#x5904;&#x7406;&#x3002;</li>
<li>web&#xFF1A;&#x63A7;&#x5236;&#x5668;&#x6A21;&#x5757;&#xFF0C;&#x7528;&#x4E8E;&#x9875;&#x9762;&#x8BF7;&#x6C42;&#x63A7;&#x5236;&#x6A21;&#x5757;&#x3002;</li>
</ol>
<p><strong>&#x642D;&#x5EFA;&#x805A;&#x5408;&#x5DE5;&#x7A0B;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
<p><strong>&#xFF08;1&#xFF09;IDEA&#x521B;&#x5EFA;maven&#x5DE5;&#x7A0B;</strong></p>
<p>&#x901A;&#x8FC7;IDEA&#x521B;&#x5EFA;&#x4E00;&#x4E2A;maven&#x7684;quickstart&#x7C7B;&#x578B;&#x9879;&#x76EE;&#xFF0C;&#x7136;&#x540E;&#x5220;&#x9664;&#x91CC;&#x9762;&#x7684;src&#x76EE;&#x5F55;&#xFF0C;&#x4FDD;&#x7559;pom.xml&#x6587;&#x4EF6;&#x5373;&#x53EF;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="SpringBoot.assets/image-20220523114657178.png" alt="image-20220523114657178"></p>
<p><strong>&#xFF08;2&#xFF09;&#x4FEE;&#x6539;pom&#x4F9D;&#x8D56;&#xFF0C;&#x4FEE;&#x6539;&#x7236;&#x5DE5;&#x7A0B;&#x9879;&#x76EE;&#x4E2D;&#x7684;pom.xml&#x6587;&#x4EF6;&#xFF0C;&#x6DFB;&#x52A0;&#x3010;springboot&#x3011;&#x4F9D;&#x8D56;&#x3002;</strong></p>
<p><img src="SpringBoot.assets/image-20220523115017174.png" alt="image-20220523115017174"></p>
<p><strong>&#xFF08;3&#xFF09;&#x521B;&#x5EFA;common&#x5B50;&#x6A21;&#x5757;</strong></p>
<p><img src="SpringBoot.assets/image-20220523115407540.png" alt="image-20220523115407540"></p>
<p>&#x5728;&#x5F39;&#x51FA;&#x754C;&#x9762;&#x4E2D;&#xFF0C;&#x9009;&#x62E9;&#x3010;quickstart&#x3011;&#x7C7B;&#x578B;&#x7684;&#x9879;&#x76EE;&#xFF0C;&#x7136;&#x540E;&#x4E0B;&#x4E00;&#x6B65;&#xFF0C;&#x586B;&#x5165;&#x5B50;&#x5DE5;&#x7A0B;&#x4FE1;&#x606F;&#x5373;&#x53EF;</p>
<p><img src="SpringBoot.assets/image-20220523115507010.png" alt="image-20220523115507010"></p>
<p> &#x5728;&#x5B50;&#x5DE5;&#x7A0B;&#x4E2D;&#xFF0C;&#x5220;&#x9664;&#x591A;&#x4F59;&#x7684;&#x3010;test&#x3011;&#x76EE;&#x5F55;&#x548C;&#x3010;App&#x3011;&#x542F;&#x52A8;&#x7C7B;&#xFF0C;&#x4FEE;&#x6539;pom&#x6587;&#x4EF6;&#xFF0C;&#x5220;&#x9664;&#x591A;&#x4F59;&#x5185;&#x5BB9;&#xFF0C;&#x6DFB;&#x52A0;&#x7236;&#x5DE5;&#x7A0B;&#x4F9D;&#x8D56;</p>
<p><img src="SpringBoot.assets/image-20220523115715146.png" alt="image-20220523115715146"></p>
<p>&#x6309;&#x7167;&#x4EE5;&#x4E0A;&#x6B65;&#x9AA4;&#x5B8C;&#x6210;&#x540E;&#x7EED;&#x5B50;&#x6A21;&#x5757;&#x7684;&#x521B;&#x5EFA;&#xFF0C;web&#x6A21;&#x5757;&#x53EF;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;webapp&#x5DE5;&#x7A0B;&#xFF0C;&#x5F62;&#x6210;&#x5982;&#x4E0B;&#x7684;&#x76EE;&#x5F55;&#x7ED3;&#x6784;</p>
<p><img src="SpringBoot.assets/image-20220523180515618.png" alt="image-20220523180515618"></p>
<p><strong>&#x7EDF;&#x4E00;&#x4F9D;&#x8D56;&#x7BA1;&#x7406;</strong></p>
<p>&#x901A;&#x8FC7;&#x524D;&#x9762;&#x7684;&#x6B65;&#x9AA4;&#xFF0C;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x5C06;&#x7236;&#x5DE5;&#x7A0B;&#x548C;&#x5B50;&#x5DE5;&#x7A0B;&#x90FD;&#x642D;&#x5EFA;&#x5B8C;&#x6210;&#x4E86;&#xFF0C;&#x5E76;&#x4E14;&#x5F15;&#x5165;&#x4E86;&#x3010;springboot&#x3011;&#x7236;&#x5DE5;&#x7A0B;&#x4F9D;&#x8D56;&#x3002;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x7BA1;&#x7406;&#x6BCF;&#x4E2A;&#x5B50;&#x5DE5;&#x7A0B;&#x7684;&#x4F9D;&#x8D56;&#xFF0C;&#x4EE5;&#x53CA;&#x5176;&#x4ED6;&#x7B2C;&#x4E09;&#x65B9;&#x4F9D;&#x8D56;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x5728;&#x7236;&#x5DE5;&#x7A0B;&#x4E2D;&#x7684;&#x3010;pom&#x3011;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x7EDF;&#x4E00;&#x7684;&#x5B9A;&#x4E49;&#x4F9D;&#x8D56;&#x7248;&#x672C;&#x3002;</p>
<p><img src="SpringBoot.assets/image-20220523181108648.png" alt="image-20220523181108648"></p>
<p>&#x5728;&#x5B50;&#x5DE5;&#x7A0B;&#x3010;-web&#x3011;&#x7684;pom&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x6DFB;&#x52A0;&#x3010;web&#x3011;&#x4F9D;&#x8D56;&#xFF0C;&#x5E76;&#x4E14;&#x521B;&#x5EFA;&#x3010;Application&#x3011;&#x542F;&#x52A8;&#x7C7B;&#x3002;</p>
<p><img src="SpringBoot.assets/image-20220523181240434.png" alt="image-20220523181240434"></p>
<p>&#x521B;&#x5EFA;&#x3010;Application&#x3011;&#x542F;&#x52A8;&#x7C7B;&#x3002;</p>
<p><img src="SpringBoot.assets/image-20220523181331566.png" alt="image-20220523181331566"></p>
<p>&#x521B;&#x5EFA;&#x3010;src/main/resources&#x3011;&#x76EE;&#x5F55;&#xFF0C;&#x65B0;&#x589E;&#x3010;application.yml&#x3011;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<p><img src="SpringBoot.assets/image-20220523181433477.png" alt="image-20220523181433477"></p>
<p>&#x521B;&#x5EFA;&#x3010;HelloController&#x3011;&#x6D4B;&#x8BD5;&#x7C7B;</p>
<p><img src="SpringBoot.assets/image-20220523181556547.png" alt="image-20220523181556547"></p>
<p>&#x542F;&#x52A8;&#x9879;&#x76EE;&#xFF0C;&#x6253;&#x5F00;&#x6D4F;&#x89C8;&#x5668;&#xFF0C;&#x8BBF;&#x95EE;&#x6D4B;&#x8BD5;&#x8DEF;&#x5F84;</p>
<p><img src="SpringBoot.assets/image-20220523181637186.png" alt="image-20220523181637186"></p>
<p>&#x5230;&#x8FD9;&#x91CC;&#xFF0C;SpringBoot&#x805A;&#x5408;&#x9879;&#x76EE;&#x5DF2;&#x7ECF;&#x521B;&#x5EFA;&#x597D;&#x4E86;&#xFF0C;&#x5E76;&#x4E14;&#x80FD;&#x591F;&#x542F;&#x52A8;&#x8BBF;&#x95EE;&#x4E86;&#x3002;&#x4E0A;&#x9762;&#x51E0;&#x4E2A;&#x5B50;&#x5DE5;&#x7A0B;&#x867D;&#x7136;&#x521B;&#x5EFA;&#x597D;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x6BCF;&#x4E2A;&#x5B50;&#x5DE5;&#x7A0B;&#x4E4B;&#x95F4;&#x5E76;&#x6CA1;&#x6709;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x5C31;&#x5C06;&#x8FD9;&#x51E0;&#x4E2A;&#x5B50;&#x5DE5;&#x7A0B;&#x8FDB;&#x884C;&#x4F9D;&#x8D56;&#x5173;&#x8054;&#x3002;</p>
<p>web-----&gt;service&#xFF08;----&gt;&#x8868;&#x793A;&#x4F9D;&#x8D56;&#xFF09;</p>
<p>service-----&gt;mapper&#xFF0C;app-common</p>
<p>mapper-----&gt;entity</p>
<p>&#x4F9D;&#x6B21;&#x7ED9;&#x6BCF;&#x4E2A;&#x5B50;&#x5DE5;&#x7A0B;&#x6DFB;&#x52A0;&#x4E0A;&#x9762;&#x7684;&#x4F9D;&#x8D56;&#x5373;&#x53EF;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Mybatis框架.html" class="navigation navigation-prev " aria-label="Previous page: Mybatis框架">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="springmvc框架.html" class="navigation navigation-next " aria-label="Next page: Springmvc框架">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"SpringBoot","level":"2.6.2","depth":2,"next":{"title":"Springmvc框架","level":"2.6.3","depth":2,"path":"books/整合/springmvc框架.md","ref":"books/整合/springmvc框架.md","articles":[]},"previous":{"title":"Mybatis框架","level":"2.6.1","depth":2,"path":"books/整合/Mybatis框架.md","ref":"books/整合/Mybatis框架.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/整合/SpringBoot.md","mtime":"2022-12-30T00:58:55.504Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

